|
Lhogho
0.0.027
|
Functions | |
| static RESULT | test_jit_compile (const char *file_name) |
| Execute in memory test. | |
| static RESULT | test_compile_exec (const char *file_name) |
| Execute compilation and then test produced file. | |
| static RESULT | build_test_case (const char *file_name) |
| Build test case file. | |
| static RESULT | process_one_file (const char *file_name) |
| Perform specified testing action on a file. | |
| RESULT | process_directory () |
| Process all files in input directory. | |
| RESULT test_jit_compile | ( | const char * | file_name | ) | [static] |
| file_name | name of the test file |
RESULT code (see error.h)Exewcute in memory test of the compiler.
{
RESULT res = SUCCESS_FULL;
RESULT res1 = SUCCESS_FULL;
FILE * input_file = NULL;
test_case_info test_info;
input_file = fopen(file_name, "rb");
if (!input_file)
{
LOG_ERROR("Couldn't open input file");
return ERR_FILE;
}
memset(&test_info, 0, sizeof(test_info));
do
{
res = extract_args(input_file, &test_info);
if (IS_ERROR(res))
{
fprintf(g_parameters.output_file, "Error extracting args for %s\n", file_name);
LOG_ERROR("Error parsing arguments");
break;
}
res |= extract_expected_results(input_file, file_name);
if (IS_ERROR(res))
{
LOG_ERROR("Error extracting expected results");
break;
}
fclose(input_file);
input_file = NULL;
res1 = execute_test(file_name, test_info);
if (IS_ERROR(res))
{
LOG_ERROR("Error executing test");
break;
}
res |= check_results(file_name, test_info, res1);
if (IS_ERROR(res))
{
LOG_ERROR("Error checking results from test");
}
clean_up(file_name);
}while (0);
SAFE_FREE(test_info.command_line_param);
SAFE_FREE(test_info.test_name);
if (input_file)
{
fclose(input_file);
}
if (res != SUCCESS_FULL)
{
++g_parameters.num_failed;
}
else
{
++g_parameters.num_passed;
}
return res;
}
| RESULT test_compile_exec | ( | const char * | file_name | ) | [static] |
| file_name | name of the test file |
RESULT code (see error.h)Call the compiler to produce executable file and then test it's execution.
{
RESULT res = SUCCESS_FULL;
RESULT res1 = SUCCESS_FULL;
FILE * input_file = NULL;
test_case_info test_info;
input_file = fopen(file_name, "rb");
if (!input_file)
{
LOG_ERROR("Couldn't open input file");
return ERR_FILE;
}
memset(&test_info, 0, sizeof(test_info));
do
{
res = extract_args(input_file, &test_info);
if (IS_ERROR(res))
{
LOG_ERROR("Error parsing arguments");
break;
}
res |= extract_expected_results(input_file, file_name);
if (IS_ERROR(res))
{
LOG_ERROR("Error extracting expected results");
break;
}
fclose(input_file);
input_file = NULL;
res |= compile_test(file_name, test_info);
if (IS_ERROR(res))
{
LOG_ERROR("Error compiling test");
break;
}
res1 = execute_test(file_name, test_info);
if (IS_ERROR(res))
{
LOG_ERROR("Error executing test");
break;
}
res |= check_results(file_name, test_info, res1);
if (IS_ERROR(res))
{
LOG_ERROR("Error checking results from test");
}
clean_up(file_name);
}while (0);
SAFE_FREE(test_info.command_line_param);
SAFE_FREE(test_info.test_name);
if (input_file)
{
fclose(input_file);
}
if (res != SUCCESS_FULL)
{
++g_parameters.num_failed;
}
else
{
++g_parameters.num_passed;
}
return res;
}
| RESULT build_test_case | ( | const char * | file_name | ) | [static] |
| file_name | name of the test file |
RESULT code (see error.h)Calls the compiler to run inmemory compilation and execution of thest case. Write down the results into the test case file.
{
RESULT res = SUCCESS_FULL;
test_case_info test_info;
memset(&test_info, 0, sizeof(test_info));
do
{
res = execute_test(file_name, test_info);
if (IS_ERROR(res))
{
LOG_ERROR("Error executing test");
break;
}
res |= import_results(file_name, test_info);
if (IS_ERROR(res))
{
LOG_ERROR("Error importing results from test");
}
}
while (0);
if (res != SUCCESS_FULL)
{
++g_parameters.num_failed;
}
else
{
++g_parameters.num_passed;
}
clean_up(file_name);
return res;
}
| RESULT process_one_file | ( | const char * | file_name | ) | [static] |
| file_name | name of the test file |
RESULT code (see error.h)Depending on command line arguments specifying tester mode call function to perform diferent test procedures on the file
{
RESULT res;
char file_buffer[1024] = "";
if (g_parameters.input_directory)
{
strcpy(file_buffer, g_parameters.input_directory);
}
else
{
strcpy(file_buffer, ".");
}
#if defined (_MSC_VER)
if (file_buffer[strlen(file_buffer) -1] != '\\')
{
strcat(file_buffer, "\\");
}
#elif defined (__GNUC__)
if (file_buffer[strlen(file_buffer) -1] != '/')
{
strcat(file_buffer, "/");
}
#endif
strcat(file_buffer, file_name);
if (g_parameters.tester_mode & MODE_BUILD)
{
res = build_test_case(file_buffer);
if (IS_ERROR(res))
{
LOG_ERROR("Error creating test case.");
return res;
}
}
if (g_parameters.tester_mode & MODE_TEST)
{
res = exec_shell(file_buffer);
if (IS_ERROR(res))
{
fprintf(g_parameters.output_file, "Error shell execution test : %s\n", file_name);
LOG_ERROR("Error executing SHELL test");
return res;
}
else if (res == SUCCESS_FULL)
{
return res;
}
res = test_jit_compile(file_buffer);
if (IS_ERROR(res))
{
fprintf(g_parameters.output_file, "Error jit execution test : %s\n", file_name);
LOG_ERROR("Error executing JIT test");
return res;
}
}
if (g_parameters.tester_mode & MODE_EXECUTE)
{
res = test_compile_exec(file_buffer);
if (IS_ERROR(res))
{
LOG_ERROR("Error compiling and executing test");
return res;
}
}
fflush(g_parameters.output_file);
return SUCCESS_FULL;
}
RESULT code (see error.h)Scan specified directory and for all test case files call process_one_file function.
{
RESULT res = SUCCESS_FULL;
#if defined (_MSC_VER)
struct _finddata_t info;
char mask[1024];
intptr_t handle;
#elif defined (__GNUC__)
DIR * dirPtr = 0;
struct dirent * dirStruct = 0;
#endif
#if defined (_MSC_VER)
if (g_parameters.input_directory)
{
strcpy(mask, g_parameters.input_directory);
if (mask[strlen(mask)-1] != '\\')
{
strcat(mask, "\\");
}
}
else
{
mask[0] = 0;
}
strcat(mask, "*.");
strcat(mask, TARGET_FILE_EXTENSION);
handle = _findfirst(mask, &info);
if (handle == -1)
{
return SUCCESS_EMPTY;
}
do
{
res = process_one_file(info.name);
} while(_findnext(handle, &info) != -1);
_findclose(handle);
#elif defined (__GNUC__)
if (g_parameters.input_directory)
{
dirPtr = opendir(g_parameters.input_directory);
}
else
{
dirPtr = opendir(".");
}
if (dirPtr == 0)
{
return ERR_FILE;
}
while ((dirStruct = readdir(dirPtr)) != 0)
{
size_t len = strlen(dirStruct->d_name);
if (!strcmp(dirStruct->d_name + len - strlen(TARGET_FILE_EXTENSION), TARGET_FILE_EXTENSION)
&& dirStruct->d_name[len - strlen(TARGET_FILE_EXTENSION) - 1] == '.')
{
res = process_one_file(dirStruct->d_name);
}
}
closedir(dirPtr);
#endif
return res;
}