Skip to content

Commit

Permalink
hm ...
Browse files Browse the repository at this point in the history
  • Loading branch information
palkh committed Jul 21, 2024
1 parent 29e4f49 commit 5bd7801
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 21 deletions.
19 changes: 17 additions & 2 deletions dev/gen_split.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
str = "this,is,a,split,test,can,you,suck,my,dick,pwease,i,like,butter,and,parmesan,"
import os
import sys
import random
import string

print(str*100)
if len(sys.argv) < 3:
print("Usage: python gen_split.py <file> <length>")
sys.exit(1)

file = sys.argv[1]
length = int(sys.argv[2])

# generate random string with ASCII chars, digits, and commas of length sys.argv[2]
random_string = ''.join(random.choice(string.ascii_letters + string.digits + ',') for _ in range(length))

# write it to file
with open(file, 'w') as f:
f.write(random_string)
1 change: 1 addition & 0 deletions dev/split.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
y3TdcM8HRpOiVKc29mQeeLMGO5zw2XIGsY9d7Worm1UFNZptZ5qacScmHby80tqwCrNv9ryTngkGSQJTuKXad7S1sPEeCWx4Rmzbn8z0zUyWr0Tr,FR3tE0R8JWM,uM21CQo,482oauILx3vvRD8hO5riOWc9D3W874,Bd5z63wgpLLbijTY3TwwC,PZZa9PhOX,6tSnbKn,jrWQHMbgrUCO0zEGZ4aDC7dr9voWuz104ODIXl2ajWP0RC8fFRRhU2wOD9FyBE2GxWM84gwx5b,PIJ,4,oHCkx8Q2SUJXgMN7u0l78lzUJ0omaJyRLP26o2zF190SbBc,AEpv9LM06iJTbAOjZx,,aN9oIc0CdQqdIZyuEzC7fVGGtdGaxUSpHIInVzrQW9xshvuojSruJJZnu0Or,yzCJNifoimcmK5rghuKxVBLvefNB2XBAsVlLLAzpWoGvIn82kvLBpaZH4C6OQDoPqfCszLnPFDgV6TCUvBrNFkY26giPWWXIPY
14 changes: 14 additions & 0 deletions dev/test.base.ecmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[info]
name = test
version = 1.0.0
license = MIT
url = x.com

[download]
mkdir $NAME-$VERSION
curl $URL > $NAME-$VERSION/download.txt

[install]
echo "INSTALLING $NAME-$VERSION" > install.txt
cp -r * $BUILD_ROOT

153 changes: 134 additions & 19 deletions dev/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ int test_split();
int test_config();
int test_make(char* spm_path);

int test_install(char* spm_path);
int test_uninstall(char* pname);

char* assemble(char** list,int count);

char CURRENT_DIR[2048];

Check warning on line 47 in dev/test.c

View workflow job for this annotation

GitHub Actions / c-linter

dev/test.c:47:6 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'CURRENT_DIR' is non-const and globally accessible, consider making it const

int main(int argc, char const *argv[])
{
dbg(1, "started spm-test");
Expand All @@ -54,9 +59,14 @@ int main(int argc, char const *argv[])
QUIET = false;
OVERWRITE = true;
DEBUG_UNIT = NULL;
// we want to chnage that later
// TODO: Add hash to test package
INSECURE = true;

getcwd(CURRENT_DIR, 2048);

if (argc < 2 || strcmp(argv[1], "help") == 0) {
printf("Usage: %s [data|ecmp|all|make|install|uninstall|move|help|split|config|get]\n", argv[0]);
printf("Usage: %s [ecmp|all|make|install|uninstall|move|help|split|config|get]\n", argv[0]);
return 0;
}

Expand All @@ -66,28 +76,59 @@ int main(int argc, char const *argv[])
return 1;
}

if (strcmp(argv[1], "ecmp") == 0) {
return test_ecmp();
} else if (strcmp(argv[1], "all") == 0) {
if (strcmp(argv[1], "all") == 0) {
int ret = 0;
ret += test_ecmp();
ret += test_move();
ret += test_get();
ret += test_split();
ret += test_config();
ret += test_make("dev/vim.ecmp");
ret += test_install("dev/vim.ecmp");
ret += test_uninstall("vim");
int leaks = check_leaks();
printf("Leaks: %d\n",leaks);
ret += leaks;
return ret;
} else if (strcmp(argv[1], "make") == 0) {
} else if (strcmp(argv[1], "ecmp") == 0) {

Check warning on line 93 in dev/test.c

View workflow job for this annotation

GitHub Actions / c-linter

dev/test.c:93:7 [readability-else-after-return]

do not use 'else' after 'return'
return test_ecmp();
} else if (strcmp(argv[1], "make") == 0) {
int EXIT = 0;
EXIT += test_make(argv[2]);
char* spm_path = NULL;
if (argc < 3) {
spm_path = strdup("dev/vim.ecmp");
} else {
spm_path = strdup(argv[2]);
}
EXIT += test_make(spm_path);

free(spm_path);

printf("Leaks: %d\n", check_leaks());
return EXIT;
}
else if (strcmp(argv[1],"install") == 0)
{
dbg(1, "installing");
init();
install_package_source(argv[2], 0);
printf("Leaks: %d\n", check_leaks());
return 0;
char* spm_path = NULL;
if (argc < 3)
{
spm_path = strdup("dev/vim.ecmp");
} else {
spm_path = strdup(argv[2]);
}
test_install(spm_path);

} else if (strcmp(argv[1], "uninstall") == 0) {
init();
uninstall(argv[2]);
char* pname = NULL;
if (argc > 3)
{
pname = strdup(argv[2]);
}
else {
pname = strdup("vim");
}
test_uninstall(pname);
return 0;
} else if (strcmp(argv[1], "move") == 0) {
return test_move();
Expand All @@ -105,6 +146,23 @@ int main(int argc, char const *argv[])

}

int test_install(char* spm_path)
{
dbg(1, "installing");
init();
install_package_source(spm_path, 0);
printf("Leaks: %d\n", check_leaks());
return 0;
}

int test_uninstall(char* pname)
{
init();
uninstall(pname);
printf("Leaks: %d\n", check_leaks());
return 0;
}

int test_move()
{

Expand Down Expand Up @@ -156,15 +214,37 @@ int test_move()


move_binaries(end_locations,8);
// Check if the move was successful
int EXIT = 0;
for (int i = 0; i < l_f_count; i++)
{
char* old_path = malloc(256);
sprintf(old_path,"%s/%s","/tmp/spm-testing/old",l_files[i]);
char* new_path = malloc(256);
sprintf(new_path,"%s/%s","/tmp/spm-testing",l_files[i]);

if(access(old_path, F_OK) != -1 || access(new_path, F_OK) == -1) {
printf("Failed to move %s\n",l_files[i]);
EXIT += 1;
break;
}

free(old_path);
free(new_path);
}
free(*end_locations);
free(end_locations);


printf("Testing move : done\n");

printf("Leaks: %d\n",check_leaks());

unsetenv("SOVIET_ROOT_DIR");
unsetenv("SOVIET_BUILD_DIR");

quit(0);
return 0;
return EXIT;
}

int test_make(char* spm_path) {
Expand Down Expand Up @@ -192,11 +272,15 @@ int test_make(char* spm_path) {
}
dbg(1,"Got %d locations for %s",p.locationsCount,p.name);


return 0;
}

int test_split()
{
{
chdir(CURRENT_DIR);
system("python3 dev/gen_split.py dev/split.txt 512");

char* split_str;
rdfile("dev/split.txt",&split_str);

Expand Down Expand Up @@ -258,23 +342,54 @@ int test_get()
init();
int EXIT = 0;


// sync with remote
repo_sync();

struct package base_pkg = {0};
char base_path[2048];
sprintf(base_path,"%s/dev/test.base.ecmp",CURRENT_DIR);
open_ecmp(base_path,&base_pkg);


struct package t_pkg;
t_pkg.name = "test";

dbg(2,"Repo: %s",getenv("SOVIET_DEFAULT_REPO"));

char* fmt = get(&t_pkg,getenv("SOVIET_DEFAULT_REPO"),"dev/test");
char out_test[2048+16 ] = {0};
strcat(out_test, CURRENT_DIR);
strcat(out_test, "/dev/test.ecmp");
dbg(3,"Copying to %s",out_test);
remove("dev/test.ecmp");
char* fmt = get(&t_pkg,getenv("SOVIET_DEFAULT_REPO"),out_test);

open_ecmp(out_test,&t_pkg);

// print fmt and all package info
printf("fmt: %s\n",fmt);
printf("name: %s\n",t_pkg.name);
printf("version: %s\n",t_pkg.version);
printf("type: %s\n",t_pkg.type);
printf("url: %s\n",t_pkg.url);

dbg(3,"Comparing %s and %s",base_pkg.name,t_pkg.name);
EXIT += strcmp(base_pkg.name,t_pkg.name);
dbg(3,"Comparing %s and %s",base_pkg.version,t_pkg.version);
EXIT += strcmp(base_pkg.version,t_pkg.version);
dbg(3,"Comparing %s and %s",base_pkg.url,t_pkg.url);
EXIT += strcmp(base_pkg.url,t_pkg.url);
// add other cmp later

free(fmt);
free(base_pkg.name);
free(base_pkg.version);
free(base_pkg.url);
free(t_pkg.name);
free(t_pkg.version);
free(t_pkg.url);

return 0;
printf("%d leaks\n",check_leaks());

return EXIT;

}

Expand Down Expand Up @@ -336,7 +451,7 @@ int test_ecmp(int type)
char* assemble(char** list,int count)
{
dbg(3,"Assembling %d strings",count);
char* string = calloc(32*count,sizeof(char));
char* string = calloc(2048*count,sizeof(char));
int i;
for (i = 0; i < count-1; i++)
{
Expand Down
5 changes: 5 additions & 0 deletions dev/vim.mod.ecmp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ make DESTDIR=$BUILD_ROOT install
echo "the package is installed"
echo "done..."

[description]
This package is really important.
It is essential to the system.
It is a dependency of many other packages.

0 comments on commit 5bd7801

Please sign in to comment.