Skip to content

Commit

Permalink
Rename tests;Set similarity based on compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
spevnev committed Nov 14, 2024
1 parent 56d8def commit e72e878
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 111 deletions.
28 changes: 19 additions & 9 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ bin="$dir/$compiler-$o_level-$g_level"
log="$bin.log"
output="$bin.out"
baseline="$BASELINE_DIR/$test.out"
is_gcc=false
if [ $(echo "$compiler" | head -c 3) = "gcc" ]; then is_gcc=true; fi


# Some tests don't work on older versions of compilers
function should_skip {
result=false

if [ $(echo "$compiler" | head -c 5) = "clang" ]; then
if [ $is_gcc = false ]; then
major_version=$("$compiler" -dumpversion | cut -d. -f1)

if [ $major_version -le 15 ]; then
Expand All @@ -58,17 +60,25 @@ function uses_shared_implementation {

# Some tests may not match baseline exactly, so they get custom target similarity percentage.
function get_similarity {
# These tests contain stdint.h types which have different typenames in gcc and clang
if [ "$test" = "struct" ]; then echo 90;
elif [ "$test" = "packed" ]; then echo 90;
result=100

if [ $is_gcc = false ]; then
# These tests contain stdint.h types which have different typenames in gcc and clang.
# Baselines are generated from gcc, so decrease its similarity for clang:
if [ "$test" = "struct" ]; then result=90;
elif [ "$test" = "packed_struct" ]; then result=90;
elif [ "$test" = "primitives" ]; then result=95;
# Clang doesn't produce DW_AT_subprogram for external functions, i.e. shared libraries
# or different CUs, so cross-CU retrieval of function signature/name doesn't work.
elif [ "$test" = "function" ]; then result=85; fi
fi

# FILE has different implementation which is up to stdio.h and it often has pointers
# that point out-of-bounds causing uprintf to print garbage from the memory, thus the
# primary goal of the test is to check that there are no errors, i.e. segfaults, leaks.
elif [ "$test" = "stdio_file" ]; then echo 1;
# Clang doesn't produce DW_AT_subprogram for external functions, i.e. shared libraries
# or different CUs, so cross-CU retrieval of function signature/name doesn't work.
elif [ "$test" = "function" ]; then echo 80;
else echo 100; fi
if [ "$test" = "stdio_file" ]; then result=10; fi

echo $result
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Different format specifiers: 100 100 100 100 100 100 100 100 100
Escaped format specifier: 100 %
(uprintf) [ERROR] Unfinished format specifier at the end of the line at tests/format.c:14.
(uprintf) [ERROR] Unfinished format specifier at the end of the line at tests/format.c:18.
(uprintf) [ERROR] Unknown format specifier "%3" at tests/format.c:22.
(uprintf) [ERROR] Unknown format specifier "%-" at tests/format.c:26.
(uprintf) [ERROR] Unfinished format specifier at the end of the line at tests/format_string.c:14.
(uprintf) [ERROR] Unfinished format specifier at the end of the line at tests/format_string.c:18.
(uprintf) [ERROR] Unknown format specifier "%3" at tests/format_string.c:22.
(uprintf) [ERROR] Unknown format specifier "%-" at tests/format_string.c:26.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Packed struct: {
Struct containing all types: {
uint8_t u8 = 255
short unsigned int u16 = 65535
unsigned int u32 = 4294967295
Expand All @@ -14,7 +14,7 @@ Packed struct: {
void *void_ptr = POINTER
int *int_ptr = POINTER (5)
float *null_ptr = NULL
char *ch_ptr = NULL
char *ch_ptr = POINTER ("c")
const char *str = POINTER ("str string")
char *const const_str = POINTER ("const_str string")
_Bool b = true
Expand Down
8 changes: 6 additions & 2 deletions tests/baselines/primitives.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ f64: -0.321000
uch: 99 ('c')
sch: 157
void_ptr: POINTER
int_ptr: POINTER (1)
null_ptr: NULL
int_ptr: POINTER (123)
str: POINTER ("const char *str")
ch_ptr: POINTER ("c")
str: POINTER ("string")
b: false
void_fun: POINTER (void void_fun())
other_fun: POINTER (int other_fun(char a, float *b, long unsigned int c))
2 changes: 1 addition & 1 deletion tests/baselines/struct.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Struct containing all types: {
void *void_ptr = POINTER
int *int_ptr = POINTER (5)
float *null_ptr = NULL
char *ch_ptr = NULL
char *ch_ptr = POINTER ("c")
const char *str = POINTER ("str string")
char *const const_str = POINTER ("const_str string")
_Bool b = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(uprintf) [ERROR] Unable to print `void*` because it can point to arbitrary data of any length. To print the pointer itself, you must get pointer (&) of "v" at tests/void.c:8.
(uprintf) [ERROR] Unable to print `void*` because it can point to arbitrary data of any length. To print the pointer itself, you must get pointer (&) of "v" at tests/void_pointers.c:8.
void* POINTER
void** POINTER, void* POINTER
void*** POINTER, void** POINTER
Expand Down
File renamed without changes.
87 changes: 0 additions & 87 deletions tests/packed.c

This file was deleted.

3 changes: 3 additions & 0 deletions tests/packed_struct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma pack(push, 1)
#include "struct.c"
#pragma pack(pop)
35 changes: 30 additions & 5 deletions tests/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
#include <stdlib.h>
#include "uprintf.h"

void void_fun(void) {}

int other_fun(char a, float *b, unsigned long c) {
(void) a;
(void) b;
(void) c;
return 1;
}

int main(void) {
int i = 1;
char c = 'c';

uint8_t u8 = 255;
uint16_t u16 = 65535;
uint32_t u32 = 4294967295;
Expand All @@ -20,11 +32,17 @@ int main(void) {
signed char uch = 'c';
unsigned char sch = -'c';

void *void_ptr = &i8;
void *null_ptr = NULL;
int i = 123;
void *void_ptr = &i;
int *int_ptr = &i;
const char *str = "const char *str";
float *null_ptr = NULL;
char *ch_ptr = &c;

const char *str = "string";

bool b = false;

void (*void_fun_v)(void) = &void_fun;
int (*other_fun_v)(char, float *, unsigned long) = &other_fun;

uprintf("u8: %S\n", &u8);
uprintf("u16: %S\n", &u16);
Expand All @@ -43,9 +61,16 @@ int main(void) {
uprintf("sch: %S\n", &sch);

uprintf("void_ptr: %S\n", &void_ptr);
uprintf("null_ptr: %S\n", &null_ptr);
uprintf("int_ptr: %S\n", &int_ptr);
uprintf("null_ptr: %S\n", &null_ptr);
uprintf("ch_ptr: %S\n", &ch_ptr);

uprintf("str: %S\n", &str);

uprintf("b: %S\n", &b);

uprintf("void_fun: %S\n", &void_fun_v);
uprintf("other_fun: %S\n", &other_fun_v);

return _upf_test_status;
}
3 changes: 3 additions & 0 deletions tests/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ int other_fun(char a, float *b, unsigned long c) {

int main(void) {
int i = 5;
char c = 'c';

Struct s = {
.u8 = 255,
Expand All @@ -71,6 +72,8 @@ int main(void) {
.void_ptr = &i,
.int_ptr = &i,
.null_ptr = NULL,
.ch_ptr = &c,

.str = "str string",
.const_str = "const_str string",

Expand Down
File renamed without changes.

0 comments on commit e72e878

Please sign in to comment.