Skip to content

Commit

Permalink
test: export: fix written path in output files
Browse files Browse the repository at this point in the history
Previously the path of the output file was written into the output file.
Now the command with which the test was run with is written instead.
Writing the path in the output is meant to indicate which application
the results were acquired from.

Signed-off-by: Ray Sointula <ray.sointula@nokia.com>
Reviewed-by: Tuomas Taipale <tuomas.taipale@nokia.com>
  • Loading branch information
Rayska authored and TuomasTaipale committed Jul 26, 2024
1 parent 6037b52 commit 5238e2a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions test/common/export_results.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
#include <unistd.h>

/** Maximum length of output path/name */
#define MAX_FILENAME_LEN 192
#define MAX_PATH_LEN 192

typedef struct {
test_common_options_t common_options;

char filename[MAX_FILENAME_LEN];
char filename[MAX_PATH_LEN];

char command[MAX_PATH_LEN];

FILE *file;

Expand Down Expand Up @@ -68,7 +70,7 @@ int test_common_parse_options(int argc, char *argv[])
env = getenv("TEST_COMMON_EXPORT");
if (env) {
gbl_data.common_options.is_export = true;
odph_strcpy(gbl_data.filename, env, MAX_FILENAME_LEN);
odph_strcpy(gbl_data.filename, env, MAX_PATH_LEN);
}

/* Find and remove option */
Expand All @@ -77,14 +79,12 @@ int test_common_parse_options(int argc, char *argv[])
gbl_data.common_options.is_export = true;
if (i + 1 < argc && argv[i + 1][0] != '-') {
odph_strcpy(gbl_data.filename, argv[i + 1],
MAX_FILENAME_LEN);
MAX_PATH_LEN);
for (j = i; j < argc - 2; j++)
argv[j] = argv[j + 2];
argc -= 2;
continue;
} else {
odph_strcpy(gbl_data.filename, argv[0],
MAX_FILENAME_LEN);
for (j = i; j < argc - 1; j++)
argv[j] = argv[j + 1];
argc--;
Expand All @@ -94,8 +94,9 @@ int test_common_parse_options(int argc, char *argv[])
}

if (gbl_data.common_options.is_export) {
odph_strcpy(gbl_data.command, argv[0], MAX_PATH_LEN);
if (strlen(gbl_data.filename) == 0)
odph_strcpy(gbl_data.filename, argv[0], MAX_FILENAME_LEN);
odph_strcpy(gbl_data.filename, argv[0], MAX_PATH_LEN);
extract_options(argc, argv);
}

Expand All @@ -107,6 +108,7 @@ int test_common_options(test_common_options_t *options)
const char *extension = ".csv";
size_t ext_len = strlen(extension);
size_t filename_len = strlen(gbl_data.filename);
size_t command_len = strlen(gbl_data.command);

memset(options, 0, sizeof(*options));

Expand All @@ -120,7 +122,7 @@ int test_common_options(test_common_options_t *options)
/* Add extension if needed */
if (filename_len < ext_len ||
strcmp(gbl_data.filename + filename_len - ext_len, extension) != 0) {
if (filename_len + ext_len >= MAX_FILENAME_LEN) {
if (filename_len + ext_len >= MAX_PATH_LEN) {
ODPH_ERR("Not enough space to add '%s' to %s\n",
extension, gbl_data.filename);
return -1;
Expand All @@ -136,8 +138,8 @@ int test_common_options(test_common_options_t *options)
}

if (gbl_data.args) {
if (fprintf(gbl_data.file, "#%.*s;%s\n", (int)filename_len,
gbl_data.filename, gbl_data.args) < 0) {
if (fprintf(gbl_data.file, "#%.*s;%s\n", (int)command_len,
gbl_data.command, gbl_data.args) < 0) {
ODPH_ERR("Writing filename and args failed\n");
return -1;
}
Expand Down

0 comments on commit 5238e2a

Please sign in to comment.