Skip to content

Commit 8b68596

Browse files
authored
Merge pull request #90 from thenetrunna/master
fix sonic tests
2 parents 1755004 + 5c235e9 commit 8b68596

File tree

5 files changed

+77
-60
lines changed

5 files changed

+77
-60
lines changed

.github/workflows/test.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
run: make dev
1818
- name: run tests
1919
run: make test
20+
- name: test libs
21+
run: make test-libs
2022

2123
build-macos:
2224
runs-on: macos-latest
@@ -28,5 +30,6 @@ jobs:
2830
run: make dev
2931
- name: run tests
3032
run: make test
33+
- name: test libs
34+
run: make test-libs
3135

32-

camel/src/camel.c

+29-25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "../include/tuwi.h"
1414

1515
#include <netlibc/fs.h>
16+
#include <netlibc/log.h>
1617

1718
#include <fcntl.h>
1819
#include <pthread.h>
@@ -25,39 +26,42 @@
2526
#include <unistd.h>
2627

2728
bool __files_equal(char *first_file, char *second_file) {
28-
char command1[1024]; // Buffer for the first checksum command
29-
char command2[1024]; // Buffer for the second checksum command
29+
FILE *file1 = fopen(first_file, "rb");
30+
FILE *file2 = fopen(second_file, "rb");
3031

31-
// Create the shell command to calculate the checksum of file1
32-
snprintf(command1, sizeof(command1), "md5sum \"%s\" 2>/dev/null", first_file);
32+
if (file1 == NULL || file2 == NULL) {
33+
perror("Error opening file");
34+
PANIC("could not open files");
35+
}
36+
37+
int byte1;
38+
int byte2;
39+
bool equal = true;
3340

34-
// Create the shell command to calculate the checksum of file2
35-
snprintf(command2, sizeof(command2), "md5sum \"%s\" 2>/dev/null",
36-
second_file);
41+
while (1) {
42+
byte1 = fgetc(file1);
43+
byte2 = fgetc(file2);
3744

38-
// Execute the shell commands using popen and capture their output
39-
FILE *fp1 = popen(command1, "r");
40-
FILE *fp2 = popen(command2, "r");
45+
if (byte1 == EOF || byte2 == EOF) {
46+
break;
47+
}
4148

42-
if (fp1 == NULL || fp2 == NULL) {
43-
perror("popen");
44-
exit(EXIT_FAILURE);
49+
if (byte1 != byte2) {
50+
equal = false;
51+
break;
52+
}
4553
}
4654

47-
char checksum1[32], checksum2[32]; // Buffer to store checksums
48-
fgets(checksum1, sizeof(checksum1), fp1);
49-
fgets(checksum2, sizeof(checksum2), fp2);
55+
// Check if both files have reached EOF at the same time
56+
if (byte1 != EOF || byte2 != EOF) {
57+
LOG(INFO, "THIS!");
58+
equal = false;
59+
}
5060

51-
// Close the file pointers
52-
pclose(fp1);
53-
pclose(fp2);
61+
fclose(file1);
62+
fclose(file2);
5463

55-
// Compare the checksums
56-
if (strcmp(checksum1, checksum2) == 0) {
57-
return true; // Checksums match
58-
} else {
59-
return false; // Checksums do not match
60-
}
64+
return equal;
6165
}
6266

6367
char *__read_file(char *path) {

makefiles/test.mk

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sonic/tests/client/makefile

+28-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sonic/tests/server/makefile

+15-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)