diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-06 14:34:33 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-12-06 14:34:33 +0900 |
commit | c83dbd0f063b7304ea6a4cfbfc663a2b864ad1ce (patch) | |
tree | fc92dc33f0ed9190cee38c3d8bcdbc5a7f32c6dc /src/fs | |
parent | 69e6c0b893b0b642f969ac8a134d043a51e393a3 (diff) | |
download | gnunet-c83dbd0f063b7304ea6a4cfbfc663a2b864ad1ce.tar.gz gnunet-c83dbd0f063b7304ea6a4cfbfc663a2b864ad1ce.zip |
-migrate meta data tests to FS. Fix BIO error
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/meta_data.c | 18 | ||||
-rw-r--r-- | src/fs/test_fs_meta_data.c | 117 |
2 files changed, 128 insertions, 7 deletions
diff --git a/src/fs/meta_data.c b/src/fs/meta_data.c index 3e2857101..7112a150a 100644 --- a/src/fs/meta_data.c +++ b/src/fs/meta_data.c | |||
@@ -1057,6 +1057,7 @@ GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
1057 | { | 1057 | { |
1058 | uint32_t size; | 1058 | uint32_t size; |
1059 | char *buf; | 1059 | char *buf; |
1060 | char *emsg; | ||
1060 | struct GNUNET_FS_MetaData *meta; | 1061 | struct GNUNET_FS_MetaData *meta; |
1061 | 1062 | ||
1062 | if (GNUNET_OK != GNUNET_BIO_read_int32 (h, | 1063 | if (GNUNET_OK != GNUNET_BIO_read_int32 (h, |
@@ -1070,11 +1071,14 @@ GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
1070 | } | 1071 | } |
1071 | if (MAX_META_DATA < size) | 1072 | if (MAX_META_DATA < size) |
1072 | { | 1073 | { |
1073 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1074 | GNUNET_asprintf (&emsg, |
1074 | _ ("Serialized metadata `%s' larger than allowed (%u > %u)"), | 1075 | _ ( |
1075 | what, | 1076 | "Serialized metadata `%s' larger than allowed (%u > %u)\n"), |
1076 | size, | 1077 | what, |
1077 | MAX_META_DATA); | 1078 | size, |
1079 | MAX_META_DATA); | ||
1080 | GNUNET_BIO_read_set_error (h, emsg); | ||
1081 | GNUNET_free (emsg); | ||
1078 | return GNUNET_SYSERR; | 1082 | return GNUNET_SYSERR; |
1079 | } | 1083 | } |
1080 | buf = GNUNET_malloc (size); | 1084 | buf = GNUNET_malloc (size); |
@@ -1119,6 +1123,10 @@ GNUNET_FS_write_meta_data (struct GNUNET_BIO_WriteHandle *h, | |||
1119 | &buf, | 1123 | &buf, |
1120 | MAX_META_DATA, | 1124 | MAX_META_DATA, |
1121 | GNUNET_FS_META_DATA_SERIALIZE_PART); | 1125 | GNUNET_FS_META_DATA_SERIALIZE_PART); |
1126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1127 | _ ("Serialized %ld bytes of metadata"), | ||
1128 | size); | ||
1129 | |||
1122 | if (-1 == size) | 1130 | if (-1 == size) |
1123 | { | 1131 | { |
1124 | GNUNET_free (buf); | 1132 | GNUNET_free (buf); |
diff --git a/src/fs/test_fs_meta_data.c b/src/fs/test_fs_meta_data.c index bee7844ea..4e7439d7b 100644 --- a/src/fs/test_fs_meta_data.c +++ b/src/fs/test_fs_meta_data.c | |||
@@ -352,19 +352,132 @@ check () | |||
352 | } | 352 | } |
353 | 353 | ||
354 | 354 | ||
355 | static int | ||
356 | test_bigmeta_rw (void) | ||
357 | { | ||
358 | static char meta[1024 * 1024 * 10]; | ||
359 | struct GNUNET_BIO_WriteHandle *wh; | ||
360 | struct GNUNET_BIO_ReadHandle *rh; | ||
361 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); | ||
362 | struct GNUNET_FS_MetaData *mdR = NULL; | ||
363 | |||
364 | memset (meta, 'b', sizeof (meta)); | ||
365 | meta[sizeof (meta) - 1] = '\0'; | ||
366 | |||
367 | wh = GNUNET_BIO_write_open_file (filename); | ||
368 | GNUNET_assert (NULL != wh); | ||
369 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, | ||
370 | "test-bigmeta-rw-int32", | ||
371 | sizeof (meta))) | ||
372 | { | ||
373 | GNUNET_BIO_write_close (wh, NULL); | ||
374 | return 1; | ||
375 | } | ||
376 | if (GNUNET_OK != GNUNET_BIO_write (wh, | ||
377 | "test-bigmeta-rw-bytes", | ||
378 | meta, | ||
379 | sizeof (meta))) | ||
380 | { | ||
381 | GNUNET_BIO_write_close (wh, NULL); | ||
382 | return 1; | ||
383 | } | ||
384 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
385 | |||
386 | rh = GNUNET_BIO_read_open_file (filename); | ||
387 | GNUNET_assert (NULL != rh); | ||
388 | GNUNET_assert (GNUNET_SYSERR == | ||
389 | GNUNET_FS_read_meta_data (rh, | ||
390 | "test-bigmeta-rw-metadata", | ||
391 | &mdR)); | ||
392 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); | ||
393 | |||
394 | GNUNET_assert (NULL == mdR); | ||
395 | |||
396 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
397 | GNUNET_free (filename); | ||
398 | return 0; | ||
399 | } | ||
400 | |||
401 | static int | ||
402 | test_fakemeta_rw (void) | ||
403 | { | ||
404 | struct GNUNET_BIO_WriteHandle *wh; | ||
405 | struct GNUNET_BIO_ReadHandle *rh; | ||
406 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); | ||
407 | struct GNUNET_FS_MetaData *mdR = NULL; | ||
408 | |||
409 | wh = GNUNET_BIO_write_open_file (filename); | ||
410 | GNUNET_assert (NULL != wh); | ||
411 | if (GNUNET_OK != GNUNET_BIO_write_int32 (wh, | ||
412 | "test-fakestring-rw-int32", | ||
413 | 2)) | ||
414 | { | ||
415 | GNUNET_BIO_write_close (wh, NULL); | ||
416 | return 1; | ||
417 | } | ||
418 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
419 | |||
420 | rh = GNUNET_BIO_read_open_file (filename); | ||
421 | GNUNET_assert (NULL != rh); | ||
422 | GNUNET_assert (GNUNET_SYSERR == | ||
423 | GNUNET_FS_read_meta_data (rh, | ||
424 | "test-fakestring-rw-metadata", | ||
425 | &mdR)); | ||
426 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); | ||
427 | |||
428 | GNUNET_assert (NULL == mdR); | ||
429 | |||
430 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
431 | GNUNET_free (filename); | ||
432 | return 0; | ||
433 | } | ||
434 | |||
435 | static int | ||
436 | test_fakebigmeta_rw (void) | ||
437 | { | ||
438 | struct GNUNET_BIO_WriteHandle *wh; | ||
439 | struct GNUNET_BIO_ReadHandle *rh; | ||
440 | char *filename = GNUNET_DISK_mktemp ("gnunet_bio"); | ||
441 | struct GNUNET_FS_MetaData *mdR = NULL; | ||
442 | int32_t wNum = 1024 * 1024 * 10; | ||
443 | |||
444 | wh = GNUNET_BIO_write_open_file (filename); | ||
445 | GNUNET_assert (NULL != wh); | ||
446 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, | ||
447 | "test-fakebigmeta-rw-int32", | ||
448 | wNum)); | ||
449 | GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); | ||
450 | |||
451 | rh = GNUNET_BIO_read_open_file (filename); | ||
452 | GNUNET_assert (NULL != rh); | ||
453 | GNUNET_assert (GNUNET_SYSERR == | ||
454 | GNUNET_FS_read_meta_data (rh, | ||
455 | "test-fakebigmeta-rw-metadata", | ||
456 | &mdR)); | ||
457 | GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); | ||
458 | |||
459 | GNUNET_assert (NULL == mdR); | ||
460 | |||
461 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); | ||
462 | GNUNET_free (filename); | ||
463 | return 0; | ||
464 | } | ||
465 | |||
355 | int | 466 | int |
356 | main (int argc, char *argv[]) | 467 | main (int argc, char *argv[]) |
357 | { | 468 | { |
358 | int failureCount = 0; | 469 | int failureCount = 0; |
359 | int i; | 470 | int i; |
360 | 471 | ||
361 | GNUNET_log_setup ("test-container-meta-data", "WARNING", NULL); | 472 | GNUNET_log_setup ("test-fs-meta-data", "WARNING", NULL); |
362 | for (i = 0; i < 255; i++) | 473 | for (i = 0; i < 255; i++) |
363 | failureCount += testMeta (i); | 474 | failureCount += testMeta (i); |
364 | for (i = 1; i < 255; i++) | 475 | for (i = 1; i < 255; i++) |
365 | failureCount += testMetaMore (i); | 476 | failureCount += testMetaMore (i); |
366 | failureCount += testMetaLink (); | 477 | failureCount += testMetaLink (); |
367 | 478 | failureCount += test_fakebigmeta_rw (); | |
479 | failureCount += test_fakemeta_rw (); | ||
480 | failureCount += test_bigmeta_rw (); | ||
368 | int ret = check (); | 481 | int ret = check (); |
369 | 482 | ||
370 | if (ret == 1) | 483 | if (ret == 1) |