Skip to content

Commit

Permalink
Tests: fix path for cpuid_tool
Browse files Browse the repository at this point in the history
When we use CMake, the 'cpuid_tool' binary is in the 'build' directory
  • Loading branch information
TheTumultuousUnicornOfDarkness committed Nov 14, 2020
1 parent 04c3ebe commit d60503c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
28 changes: 25 additions & 3 deletions tests/convert_instlatx64.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include "../libcpuid/libcpuid.h"

#define LINE_LEN 60
#define FILENAME_LEN 128
#define PATH_MAX 1024
#define CMD_LEN 256
#define EXT_CPUID 0x80000000

Expand Down Expand Up @@ -58,8 +60,9 @@ int main(int argc, char *argv[])
{
int assigned, subleaf;
uint32_t addr, prev_addr, eax, ebx, ecx, edx;
char line[LINE_LEN], raw_filename[FILENAME_LEN], report_filename[FILENAME_LEN], cmd[CMD_LEN];
FILE *fin = NULL, *fout = NULL;
char line[LINE_LEN], raw_filename[FILENAME_LEN], report_filename[FILENAME_LEN];
char libcpuid_directory[PATH_MAX], cpuid_tool[PATH_MAX], cmd[CMD_LEN];
FILE *fin = NULL, *fout = NULL, *ftmp = NULL;
struct cpu_raw_data_t *raw = &(struct cpu_raw_data_t) {};

if(argc < 3)
Expand All @@ -74,6 +77,20 @@ int main(int argc, char *argv[])
snprintf(report_filename, FILENAME_LEN, "%s_report.txt", output_filename);
memset(raw, 0xff, sizeof(struct cpu_raw_data_t)); // ffffffff ffffffff ffffffff ffffffff means data is missing in output test file

/* Find libcpuid root directory */
if((ftmp = popen("git rev-parse --show-toplevel", "r")) == NULL)
{
perror("Failed to run 'git' command");
return 1;
}
if(fgets(libcpuid_directory, PATH_MAX, ftmp) == NULL)
{
perror("Failed to get source directory");
return 1;
}
pclose(ftmp);
libcpuid_directory[strlen(libcpuid_directory) - 1] = '\0';

/* Open files */
if((fin = fopen(input_filename, "r")) == NULL)
{
Expand Down Expand Up @@ -128,7 +145,12 @@ int main(int argc, char *argv[])
fclose(fout);

/* Invoke cpuid_tool */
snprintf(cmd, CMD_LEN, "../cpuid_tool/cpuid_tool --load=%s --report --outfile=%s", raw_filename, report_filename);
snprintf(cpuid_tool, PATH_MAX, "%s/build/cpuid_tool/cpuid_tool", libcpuid_directory);
if(access(cpuid_tool, F_OK) == 0)
snprintf(cmd, CMD_LEN, "%s --load=%s --report --outfile=%s", cpuid_tool, raw_filename, report_filename);
else
snprintf(cmd, CMD_LEN, "%s/cpuid_tool/cpuid_tool --load=%s --report --outfile=%s", libcpuid_directory, raw_filename, report_filename);

if(system(cmd))
{
perror("Failed to load raw file in cpuid_tool");
Expand Down
6 changes: 4 additions & 2 deletions tests/update_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

TESTS_DIR="$(dirname "$(realpath "$0")")"
LIBCPUID_DIR="$(dirname "$TESTS_DIR")"
LIBCPUID_CPUID_TOOL="$(find "$LIBCPUID_DIR" -name cpuid_tool -type f)"
LIBCPUID_CREATE_TEST="$(find "$LIBCPUID_DIR" -name create_test.py -type f)"

test_files=$(find "$TESTS_DIR" -name '*.test')
for test_file in $test_files; do
Expand All @@ -13,7 +15,7 @@ for test_file in $test_files; do
fi
echo "$line" >> "$TMP_DIR/raw.txt"
done < "$test_file"
"$LIBCPUID_DIR/cpuid_tool/cpuid_tool" --load="$TMP_DIR/raw.txt" --report > "$TMP_DIR/report.txt"
"$LIBCPUID_DIR/tests/create_test.py" "$TMP_DIR/raw.txt" "$TMP_DIR/report.txt" > "$test_file"
"$LIBCPUID_CPUID_TOOL" --load="$TMP_DIR/raw.txt" --report > "$TMP_DIR/report.txt"
"$LIBCPUID_CREATE_TEST" "$TMP_DIR/raw.txt" "$TMP_DIR/report.txt" > "$test_file"
rm -rf "$TMP_DIR"
done

0 comments on commit d60503c

Please sign in to comment.