Skip to content

Commit

Permalink
enc2 tester: knobs --reps N, --emit ( __emit) and --byte (.bytes) stmts
Browse files Browse the repository at this point in the history
(cherry picked from commit 43653e40e995b8d696ff3acbb736928652dd151e)
  • Loading branch information
mjcharne authored and markcharney committed Mar 23, 2020
1 parent f91e868 commit d738599
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions src/enc2test/test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*BEGIN_LEGAL
Copyright (c) 2019 Intel Corporation
nCopyright (c) 2019 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,7 @@ END_LEGAL */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "xed-histogram.h"

typedef xed_uint32_t (*test_func_t)(xed_uint8_t* output_buffer);
Expand All @@ -43,13 +44,35 @@ xed_state_t dstate;

xed_histogram_t histo;

int enable_emit=0;
int enable_emit_byte=0;

static void dump(xed_uint8_t* buf, xed_uint32_t len) {
xed_uint_t i;
for(i=0;i<len;i++) {
printf("%02x ",buf[i]);
}
}

static void dump_emit_byte(xed_uint8_t* buf, xed_uint32_t len) {
xed_uint_t i;
printf(".byte ");
for(i=0;i<len;i++) {
if (i>0)
printf(", ");
printf("0x%02x", buf[i]);
}
printf("\n");
}

static void dump_emit(xed_uint8_t* buf, xed_uint32_t len) {
xed_uint_t i;
for(i=0;i<len;i++) {
printf("__emit 0x%02x\n", buf[i]);
}
printf("\n");
}

xed_uint64_t total = 0;
xed_uint_t reps = 100;
int execute_test(int test_id, test_func_t* base, char const* fn_name, xed_iclass_enum_t ref_iclass) {
Expand Down Expand Up @@ -103,6 +126,13 @@ int execute_test(int test_id, test_func_t* base, char const* fn_name, xed_iclass
printf("\n");
return 1;
}

if (enable_emit) {
dump_emit(output_buffer, enclen);
}
else if (enable_emit_byte) {
dump_emit_byte(output_buffer, enclen);
}
}
else {
printf("\ttest id %d ERROR: %s (%s)\n", test_id, xed_error_enum_t2str(err), fn_name);
Expand Down Expand Up @@ -183,12 +213,24 @@ int main(int argc, char** argv) {
m = i;
printf("Total tests %d\n",m);
for(i=1;i<argc;i++) {
if (strcmp(argv[i],"--histo")==0) {
if (strcmp(argv[i],"--reps")==0) {
assert( i+1 < argc );
reps = atoi(argv[i+1]);
i = i + 1;
}
else if (strcmp(argv[i],"--histo")==0) {
enable_histogram = 1;
}
else if (strcmp(argv[i],"--emit")==0) {
enable_emit = 1;
}
else if (strcmp(argv[i],"--byte")==0) {
enable_emit_byte = 1;
}
else if ( strcmp(argv[i],"-h")==0 ||
strcmp(argv[i],"--help")==0 ) {
fprintf(stderr,"%s [-h|--help] [--histo] [test_id ...]\n", argv[0]);
fprintf(stderr,"%s [-h|--help] [--histo] [--byte|--emit] [--reps N] [test_id ...]\n",
argv[0]);
exit(0);
}
else {
Expand All @@ -210,6 +252,11 @@ int main(int argc, char** argv) {
}
}
}

if (enable_emit_byte && enable_emit) {
printf("Cannot specify --byte and --emit in the same run\n");
exit(1);
}
if (specific_tests==0) {
printf("Testing all...\n");
errors = test_all(base, str_table, iclass_table);
Expand Down

0 comments on commit d738599

Please sign in to comment.