From: Michael Tremer Date: Thu, 28 May 2020 14:17:00 +0000 (+0000) Subject: test: Generate random temporary files X-Git-Tag: 0.9.2~38 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Flibloc.git;a=commitdiff_plain;h=6254dca603544690c3ee71e605d560ca24d75dc3 test: Generate random temporary files Debian runs the testsuite in parallel which fails when mutliple process write to the same file at the same time. This patch will now create and later delete a temporary file. Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index fff6aef..570ec3a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -295,7 +295,6 @@ TESTS = \ src/test-signature CLEANFILES += \ - test.db \ testdata.db testdata.db: examples/python/create-database.py diff --git a/src/test-as.c b/src/test-as.c index 7a2f34e..a2d0ed5 100644 --- a/src/test-as.c +++ b/src/test-as.c @@ -49,7 +49,7 @@ int main(int argc, char** argv) { loc_as_unref(as); } - FILE* f = fopen("test.db", "w+"); + FILE* f = tmpfile(); if (!f) { fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); exit(EXIT_FAILURE); @@ -60,17 +60,10 @@ int main(int argc, char** argv) { fprintf(stderr, "Could not write database: %s\n", strerror(-err)); exit(EXIT_FAILURE); } - fclose(f); loc_writer_unref(writer); // And open it again from disk - f = fopen("test.db", "r"); - if (!f) { - fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - struct loc_database* db; err = loc_database_new(ctx, &db, f); if (err) { @@ -125,6 +118,7 @@ int main(int argc, char** argv) { loc_database_enumerator_unref(enumerator); loc_database_unref(db); loc_unref(ctx); + fclose(f); return EXIT_SUCCESS; } diff --git a/src/test-country.c b/src/test-country.c index 25baf74..4a9c9c1 100644 --- a/src/test-country.c +++ b/src/test-country.c @@ -75,7 +75,7 @@ int main(int argc, char** argv) { } loc_country_unref(country); - FILE* f = fopen("test.db", "w+"); + FILE* f = tmpfile(); if (!f) { fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); exit(EXIT_FAILURE); @@ -86,17 +86,9 @@ int main(int argc, char** argv) { fprintf(stderr, "Could not write database: %s\n", strerror(-err)); exit(EXIT_FAILURE); } - fclose(f); - loc_writer_unref(writer); // And open it again from disk - f = fopen("test.db", "r"); - if (!f) { - fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - struct loc_database* db; err = loc_database_new(ctx, &db, f); if (err) { @@ -114,6 +106,7 @@ int main(int argc, char** argv) { loc_database_unref(db); loc_unref(ctx); + fclose(f); return EXIT_SUCCESS; } diff --git a/src/test-database.c b/src/test-database.c index 6f20a59..4fdb774 100644 --- a/src/test-database.c +++ b/src/test-database.c @@ -135,7 +135,7 @@ int main(int argc, char** argv) { exit(EXIT_FAILURE); } - FILE* f = fopen("test.db", "w+"); + FILE* f = tmpfile(); if (!f) { fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); exit(EXIT_FAILURE); @@ -148,16 +148,7 @@ int main(int argc, char** argv) { } loc_writer_unref(writer); - // Close the file - fclose(f); - // And open it again from disk - f = fopen("test.db", "r"); - if (!f) { - fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - struct loc_database* db; err = loc_database_new(ctx, &db, f); if (err) { @@ -177,8 +168,8 @@ int main(int argc, char** argv) { // Close the database loc_database_unref(db); - loc_unref(ctx); + fclose(f); return EXIT_SUCCESS; } diff --git a/src/test-network.c b/src/test-network.c index eb2a82f..24355a9 100644 --- a/src/test-network.c +++ b/src/test-network.c @@ -120,7 +120,7 @@ int main(int argc, char** argv) { // Set ASN loc_network_set_asn(network4, 1024); - FILE* f = fopen("test.db", "w+"); + FILE* f = tmpfile(); if (!f) { fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); exit(EXIT_FAILURE); @@ -131,8 +131,6 @@ int main(int argc, char** argv) { fprintf(stderr, "Could not write database: %s\n", strerror(-err)); exit(EXIT_FAILURE); } - fclose(f); - loc_writer_unref(writer); loc_network_unref(network1); @@ -142,12 +140,6 @@ int main(int argc, char** argv) { loc_network_tree_unref(tree); // And open it again from disk - f = fopen("test.db", "r"); - if (!f) { - fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - struct loc_database* db; err = loc_database_new(ctx, &db, f); if (err) { @@ -172,6 +164,7 @@ int main(int argc, char** argv) { loc_network_unref(network1); loc_unref(ctx); + fclose(f); return EXIT_SUCCESS; } diff --git a/src/test-signature.c b/src/test-signature.c index daebef2..cbbe15f 100644 --- a/src/test-signature.c +++ b/src/test-signature.c @@ -61,7 +61,7 @@ int main(int argc, char** argv) { if (err < 0) exit(EXIT_FAILURE); - FILE* f = fopen("test.db", "w+"); + FILE* f = tmpfile(); if (!f) { fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); exit(EXIT_FAILURE); @@ -74,16 +74,7 @@ int main(int argc, char** argv) { } loc_writer_unref(writer); - // Close the file - fclose(f); - // And open it again from disk - f = fopen("test.db", "r"); - if (!f) { - fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - struct loc_database* db; err = loc_database_new(ctx, &db, f); if (err) { @@ -114,8 +105,8 @@ int main(int argc, char** argv) { // Close the database loc_database_unref(db); - loc_unref(ctx); + fclose(f); fclose(private_key1); fclose(private_key2);