forked from vieter-v/vieter
Compare commits
No commits in common. "b0212b81620f8c43d691e5d50d2c4f180a20d8c9" and "4c56351132026bc003b3d09ee0a47f8198098375" have entirely different histories.
b0212b8162
...
4c56351132
|
|
@ -107,6 +107,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
|
||||||
|
|
||||||
a := C.archive_read_new()
|
a := C.archive_read_new()
|
||||||
entry := C.archive_entry_new()
|
entry := C.archive_entry_new()
|
||||||
|
mut r := 0
|
||||||
|
|
||||||
// Sinds 2020, all newly built Arch packages use zstd
|
// Sinds 2020, all newly built Arch packages use zstd
|
||||||
C.archive_read_support_filter_zstd(a)
|
C.archive_read_support_filter_zstd(a)
|
||||||
|
|
@ -115,7 +116,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
|
||||||
C.archive_read_support_format_tar(a)
|
C.archive_read_support_format_tar(a)
|
||||||
|
|
||||||
// TODO find out where does this 10240 come from
|
// TODO find out where does this 10240 come from
|
||||||
r := C.archive_read_open_filename(a, &char(pkg_path.str), 10240)
|
r = C.archive_read_open_filename(a, &char(pkg_path.str), 10240)
|
||||||
|
|
||||||
if r != C.ARCHIVE_OK {
|
if r != C.ARCHIVE_OK {
|
||||||
return error('Failed to open package.')
|
return error('Failed to open package.')
|
||||||
|
|
@ -125,6 +126,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
|
||||||
C.archive_read_free(a)
|
C.archive_read_free(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mut buf := voidptr(0)
|
||||||
mut files := []string{}
|
mut files := []string{}
|
||||||
mut pkg_info := PkgInfo{}
|
mut pkg_info := PkgInfo{}
|
||||||
|
|
||||||
|
|
@ -142,7 +144,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
|
||||||
size := C.archive_entry_size(entry)
|
size := C.archive_entry_size(entry)
|
||||||
|
|
||||||
// TODO can this unsafe block be avoided?
|
// TODO can this unsafe block be avoided?
|
||||||
buf := unsafe { malloc(size) }
|
buf = unsafe { malloc(size) }
|
||||||
defer {
|
defer {
|
||||||
unsafe {
|
unsafe {
|
||||||
free(buf)
|
free(buf)
|
||||||
|
|
@ -150,8 +152,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
|
||||||
}
|
}
|
||||||
C.archive_read_data(a, buf, size)
|
C.archive_read_data(a, buf, size)
|
||||||
|
|
||||||
pkg_text := unsafe { buf.vstring_with_len(size).clone() }
|
pkg_text := unsafe { cstring_to_vstring(buf) }
|
||||||
|
|
||||||
pkg_info = parse_pkg_info_string(pkg_text) ?
|
pkg_info = parse_pkg_info_string(pkg_text) ?
|
||||||
} else {
|
} else {
|
||||||
C.archive_read_data_skip(a)
|
C.archive_read_data_skip(a)
|
||||||
|
|
|
||||||
59
test.py
59
test.py
|
|
@ -6,7 +6,6 @@ import uuid
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
# A list of words the program can choose from
|
# A list of words the program can choose from
|
||||||
|
|
@ -17,27 +16,27 @@ WORDS = ["alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf",
|
||||||
SEED = 2022
|
SEED = 2022
|
||||||
|
|
||||||
|
|
||||||
def random_words(words, min_len, max_len=None):
|
def random_words(max_len=None, min_len=1):
|
||||||
"""
|
"""
|
||||||
Returns a random list of words, with a length randomly choosen between
|
Returns a random list of words, with a length randomly choosen between
|
||||||
min_len and max_len. If max_len is None, it is equal to the length of
|
min_len and max_len. If max_len is None, it is equal to the length of
|
||||||
words.
|
WORDS.
|
||||||
"""
|
"""
|
||||||
if max_len is None:
|
if max_len is None:
|
||||||
max_len = len(words)
|
max_len = len(WORDS)
|
||||||
|
|
||||||
k = random.randint(min_len, max_len)
|
k = random.randint(min_len, max_len)
|
||||||
|
|
||||||
return random.choices(words, k=k)
|
return random.choices(WORDS, k=k)
|
||||||
|
|
||||||
def random_lists(words, n, min_len, max_len=None):
|
def random_lists(n, max_len=None, min_len=1):
|
||||||
return [random_words(words, min_len, max_len) for _ in range(n)]
|
return [random_words(max_len, min_len) for _ in range(n)]
|
||||||
|
|
||||||
def create_random_pkginfo(words, name_min_len, name_max_len):
|
def create_random_pkginfo():
|
||||||
"""
|
"""
|
||||||
Generates a random .PKGINFO
|
Generates a random .PKGINFO
|
||||||
"""
|
"""
|
||||||
name = "-".join(random_words(words, name_min_len, name_max_len))
|
name = "-".join(random_words(3))
|
||||||
ver = "0.1.0" # doesn't matter what it is anyways
|
ver = "0.1.0" # doesn't matter what it is anyways
|
||||||
|
|
||||||
# TODO add random dependencies (all types)
|
# TODO add random dependencies (all types)
|
||||||
|
|
@ -51,7 +50,7 @@ def create_random_pkginfo(words, name_min_len, name_max_len):
|
||||||
|
|
||||||
return "\n".join(f"{key} = {value}" for key, value in data.items())
|
return "\n".join(f"{key} = {value}" for key, value in data.items())
|
||||||
|
|
||||||
def create_random_package(tmpdir, words, pkg_name_min_len, pkg_name_max_len, min_files, max_files, min_filename_len, max_filename_len):
|
def create_random_package(tmpdir):
|
||||||
"""
|
"""
|
||||||
Creates a random, but valid Arch package, using the provided tmpdir. Output
|
Creates a random, but valid Arch package, using the provided tmpdir. Output
|
||||||
is the path to the created package tarball.
|
is the path to the created package tarball.
|
||||||
|
|
@ -70,13 +69,11 @@ def create_random_package(tmpdir, words, pkg_name_min_len, pkg_name_max_len, min
|
||||||
with tarfile.open(tar_path, "w") as tar:
|
with tarfile.open(tar_path, "w") as tar:
|
||||||
# Add random .PKGINFO file
|
# Add random .PKGINFO file
|
||||||
pkginfo_file = sub_path / ".PKGINFO"
|
pkginfo_file = sub_path / ".PKGINFO"
|
||||||
pkginfo_file.write_text(create_random_pkginfo(words, pkg_name_min_len, pkg_name_max_len))
|
pkginfo_file.write_text(create_random_pkginfo())
|
||||||
tar.add(pkginfo_file, filter=remove_prefix)
|
tar.add(pkginfo_file, filter=remove_prefix)
|
||||||
|
|
||||||
# Create random files
|
# Create random files
|
||||||
file_count = random.randint(min_files, max_files)
|
for words in random_lists(10, max_len=5):
|
||||||
|
|
||||||
for words in random_lists(words, file_count, min_filename_len, max_filename_len):
|
|
||||||
path = sub_path / 'usr' / ('/'.join(words) + ".txt")
|
path = sub_path / 'usr' / ('/'.join(words) + ".txt")
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
path.write_text(' '.join(words))
|
path.write_text(' '.join(words))
|
||||||
|
|
@ -86,19 +83,14 @@ def create_random_package(tmpdir, words, pkg_name_min_len, pkg_name_max_len, min
|
||||||
return tar_path
|
return tar_path
|
||||||
|
|
||||||
|
|
||||||
async def check_output(r):
|
async def upload_random_package(dir, sem):
|
||||||
good = {"File already exists.", "Package added successfully."}
|
tar_path = create_random_package(dir)
|
||||||
txt = await r.text()
|
|
||||||
|
|
||||||
return (txt in good, txt)
|
|
||||||
|
|
||||||
|
|
||||||
async def upload_random_package(tar_path, sem):
|
|
||||||
async with sem:
|
async with sem:
|
||||||
with open(tar_path, 'rb') as f:
|
with open(tar_path, 'rb') as f:
|
||||||
async with aiohttp.ClientSession() as s:
|
async with aiohttp.ClientSession() as s:
|
||||||
async with s.post("http://localhost:8000/publish", data=f.read(), headers={"x-api-key": "test"}) as r:
|
async with s.post("http://localhost:8000/publish", data=f.read(), headers={"x-api-key": "test"}) as r:
|
||||||
return await check_output(r)
|
print(r.text)
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|
@ -107,14 +99,6 @@ async def main():
|
||||||
parser.add_argument("count", help="How many packages to upload.", default=1, type=int)
|
parser.add_argument("count", help="How many packages to upload.", default=1, type=int)
|
||||||
parser.add_argument("-p", "--parallel", help="How many uploads to run in parallel.", default=1, type=int)
|
parser.add_argument("-p", "--parallel", help="How many uploads to run in parallel.", default=1, type=int)
|
||||||
parser.add_argument("-s", "--seed", help="Seed for the randomizer.", default=SEED, type=int)
|
parser.add_argument("-s", "--seed", help="Seed for the randomizer.", default=SEED, type=int)
|
||||||
parser.add_argument("--min-files", help="Minimum amount of files to add to an archive.", default=5, type=int)
|
|
||||||
parser.add_argument("--max-files", help="Max amount of files to add to an archive.", default=10, type=int)
|
|
||||||
parser.add_argument("--min-filename-length", help="Minimum amount of words to use for generating filenames.", default=1, type=int)
|
|
||||||
parser.add_argument("--max-filename-length", help="Max amount of words to use for generating filenames.", default=5, type=int)
|
|
||||||
parser.add_argument("--min-pkg-name-length", help="Minimum amount of words to use for creating package name.", default=1, type=int)
|
|
||||||
parser.add_argument("--max-pkg-name-length", help="Max amount of words to use for creating package name.", default=3, type=int)
|
|
||||||
parser.add_argument("--words", help="Words to use for randomizing.", default=WORDS, type=lambda s: s.split(','))
|
|
||||||
# parser.add_argument("--words", help="Words to use for randomizing.", default=WORDS, type=)
|
|
||||||
# parser.add_argument("-d", "--dir", help="Directory to create ")
|
# parser.add_argument("-d", "--dir", help="Directory to create ")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
@ -122,23 +106,10 @@ async def main():
|
||||||
sem = asyncio.BoundedSemaphore(args.parallel)
|
sem = asyncio.BoundedSemaphore(args.parallel)
|
||||||
random.seed(args.seed)
|
random.seed(args.seed)
|
||||||
|
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
tmpdir = Path(tmpdirname)
|
tmpdir = Path(tmpdirname)
|
||||||
|
|
||||||
# We generate the tars in advance because they're not async anyways
|
await asyncio.gather(*(upload_random_package(tmpdir, sem) for _ in range(args.count)))
|
||||||
print("Generating tarballs...")
|
|
||||||
tars = {
|
|
||||||
create_random_package(tmpdir, args.words, args.min_pkg_name_length, args.max_pkg_name_length, args.min_files, args.max_files, args.min_filename_length, args.max_filename_length)
|
|
||||||
for _ in range(args.count)
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Sending requests...")
|
|
||||||
res = await asyncio.gather(*(upload_random_package(tar, sem) for tar in tars))
|
|
||||||
|
|
||||||
# Generate status report
|
|
||||||
if any(not x[0] for x in res):
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue