Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdb unit test for sorting big lists #130

Closed
wants to merge 4 commits into from

Conversation

GovanifY
Copy link
Contributor

For now this unit test triggers a crash, related to radareorg/radare2#7079

@radare
Copy link
Collaborator

radare commented Mar 24, 2017

test_sdb.c:54:16: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Wint-conversion]
                sdb_set (db, i-1, i, 0);
                             ^~~
../../src/sdb.h:146:31: note: passing argument to parameter 'key' here
int sdb_set(Sdb*, const char *key, const char *data, ut32 cas);
                              ^
test_sdb.c:54:21: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Wint-conversion]
                sdb_set (db, i-1, i, 0);
                                  ^
../../src/sdb.h:146:48: note: passing argument to parameter 'data' here
int sdb_set(Sdb*, const char *key, const char *data, ut32 cas);
                                               ^
2 warnings generated.

@radare
Copy link
Collaborator

radare commented Mar 24, 2017

thats why it segfaults :P

@radare
Copy link
Collaborator

radare commented Mar 24, 2017

fixed your test case and its not crashing at all this is not a valid test for your issue

@radare
Copy link
Collaborator

radare commented Mar 24, 2017

also you are not checking if the resulting list is sorted or not

@GovanifY
Copy link
Contributor Author

I thougt we didn't had in that case as long as it didn't crashed. Argh back to reproducing then, sorry >_>

@radare
Copy link
Collaborator

radare commented Mar 24, 2017

i am sorting 10 million items in this SdbList without any stack exhaustion or crash problem

@radare
Copy link
Collaborator

radare commented Mar 24, 2017

diff --git a/test/unit/test_sdb.c b/test/unit/test_sdb.c
index 95f29f6..4d76430 100644
--- a/test/unit/test_sdb.c
+++ b/test/unit/test_sdb.c
@@ -50,11 +50,12 @@ static int __cmp_asc(const void *a, const void *b) {
 bool test_sdb_list_big(void) {
        Sdb *db = sdb_new (NULL, NULL, false);
        int i;
-       for ( i=1; i < 100000; i++) {
-               sdb_set (db, i-1, i, 0);
+       for ( i=0; i < 10000; i++) {
+               sdb_num_set (db, sdb_fmt (0, "%d", i), i + 1, 0);
        }
        SdbList *list = sdb_foreach_list (db, true);
-       ls_sort(list, __cmp_asc);
+       ls_sort (list, __cmp_asc);
+// TODO: verify if its sorted
        sdb_free (db);
        mu_end;
 }

@GovanifY
Copy link
Contributor Author

Patch applied, any idea on how to reproduce the issue then?

@GovanifY
Copy link
Contributor Author

Also confirm it works here too even though that was to be expected: test_sdb_list_big OK

@GovanifY
Copy link
Contributor Author

Got a segfault at 10M here, will try to reproduce at lower count and add here. Tooked a lot of time tho

@radare
Copy link
Collaborator

radare commented Mar 25, 2017 via email

@radare
Copy link
Collaborator

radare commented Mar 25, 2017 via email

@GovanifY
Copy link
Contributor Author

Test is pretty slow in its current form but works™

@GovanifY
Copy link
Contributor Author

There is a chance, for mmap, I'll check that later, thanks for pointing out

}
SdbList *list = sdb_foreach_list (db, true);
ls_sort (list, __cmp_asc);
// TODO: verify if its sorted
Copy link
Contributor

@alvarofe alvarofe Mar 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are sorting twice since sdb_foreach_list with the true flag already does the same operation as below

@alvarofe
Copy link
Contributor

Working on this btw

@alvarofe
Copy link
Contributor

Fixed in master. I lowered the amount to sort to 500000 just to save time when testing.

Test again please and tell me.

@alvarofe alvarofe closed this Mar 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants