]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
New testutils function open_srcdir_file.
authorNiels Möller <nisse@lysator.liu.se>
Fri, 27 Jun 2025 18:54:27 +0000 (20:54 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Fri, 27 Jun 2025 18:54:27 +0000 (20:54 +0200)
ChangeLog
testsuite/testutils.c
testsuite/testutils.h
testsuite/yarrow-test.c

index 5c4898ebd2dfd3d02ad9b50d91d37d5120ec7f9d..509144ae68c8a6afeeac1354f32681019993feaa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-06-27  Niels Möller  <nisse@lysator.liu.se>
+
+       * testsuite/testutils.c (open_srcdir_file): New function.
+       * testsuite/yarrow-test.c (open_file): Deleted function.
+       (test_main): Use open_srcdir_file instead.
+
 2025-06-26  Niels Möller  <nisse@lysator.liu.se>
 
        Cherry-picked from branch nettle-3.10-fixes:
index 9ab354a368837e1d910f7f5f849787f7c2eba0ae..613bffd1c6737277b9cca01f9b965d1b14b92a15 100644 (file)
@@ -122,6 +122,33 @@ print_hex(size_t length, const uint8_t *data)
   printf("\n");
 }
 
+/* Tries opening the file in $srcdir, if set, otherwise the current
+ * working directory */
+FILE *
+open_srcdir_file (const char *name)
+{
+  const char *srcdir = getenv("srcdir");
+  FILE *f;
+  if (srcdir && srcdir[0])
+    {
+      size_t size  = strlen(name) + strlen(srcdir) + 2;
+      char *buf = xalloc(size);
+      snprintf(buf, size, "%s/%s", srcdir, name);
+
+      f = fopen(buf, "r");
+      free(buf);
+    }
+  else
+    f = fopen(name, "r");
+
+  if (!f)
+    {
+      fprintf(stderr, "Failed to open '%s': %s\n", name, strerror(errno));
+      FAIL();
+    }
+  return f;
+}
+
 int verbose = 0;
 int test_side_channel = 0;
 
index 49b813ab85ec8e54d159ca5747d166e7befd7dbe..34090aa723abda03d2d62dc394057b0b6503afd5 100644 (file)
@@ -68,6 +68,9 @@ tstring_print_hex(const struct tstring *s);
 void
 print_hex(size_t length, const uint8_t *data);
 
+FILE *
+open_srcdir_file (const char *name);
+
 /* If side-channel tests are requested, attach valgrind annotations on
    given memory area. */
 void
index 2310dbb915e3ed308d9064e29b863e8f9411886d..dfb9ef1d63b8f581f4fe04f703cd40b05b0e7753 100644 (file)
@@ -4,9 +4,6 @@
 
 #include "macros.h"
 
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -36,28 +33,6 @@ get_event(FILE *f, struct sha256_ctx *hash,
   return 1;
 }
 
-static FILE *
-open_file(const char *name)
-{
-  /* Tries opening the file in $srcdir, if set, otherwise the current
-   * working directory */
-
-  const char *srcdir = getenv("srcdir");
-  if (srcdir && srcdir[0])
-    {
-      FILE *f;
-      char *buf = xalloc(strlen(name) + strlen(srcdir) + 10);
-      sprintf(buf, "%s/%s", srcdir, name);
-
-      f = fopen(buf, "r");
-      free(buf);
-      return f;
-    }
-
-  /* Opens the file in text mode. */
-  return fopen(name, "r");
-}
-
 void
 test_main(void)
 {
@@ -112,15 +87,8 @@ test_main(void)
   
   ASSERT(!yarrow256_is_seeded(&yarrow));
 
-  input = open_file("gold-bug.txt");
+  input = open_srcdir_file("gold-bug.txt");
 
-  if (!input)
-    {
-      fprintf(stderr, "Couldn't open `gold-bug.txt', errno = %d\n",
-              errno);
-      FAIL();
-    }
-  
   while (get_event(input, &input_hash, &c, &t))
     {
       uint8_t buf[8];