+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:
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;
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
#include "macros.h"
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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)
{
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];