Skip to content

Commit

Permalink
Add C harnesses and compile tests for gcc/clang, update harness metho…
Browse files Browse the repository at this point in the history
…d for unlimited indices
  • Loading branch information
novafacing committed Mar 18, 2024
1 parent e8851a8 commit e14afdf
Show file tree
Hide file tree
Showing 11 changed files with 5,217 additions and 421 deletions.
1 change: 1 addition & 0 deletions harness/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.o
24 changes: 24 additions & 0 deletions harness/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

cat <<EOF > "${SCRIPT_DIR}/tsffs.h"
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#ifdef __GNUC__
#ifdef __i386__
$(cat "${SCRIPT_DIR}/tsffs-gcc-x86.h")
#elif __x86_64__
$(cat "${SCRIPT_DIR}/tsffs-gcc-x86_64.h")
#elif __riscv && !__LP64__
$(cat "${SCRIPT_DIR}/tsffs-gcc-riscv32.h")
#elif __riscv && __LP64__
$(cat "${SCRIPT_DIR}/tsffs-gcc-riscv64.h")
#elif __aarch64__
$(cat "${SCRIPT_DIR}/tsffs-gcc-aarch64.h")
#elif __arm__
$(cat "${SCRIPT_DIR}/tsffs-gcc-arm32.h")
#endif
#endif
EOF
92 changes: 92 additions & 0 deletions harness/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#ifdef SINGLE_FILE
#include "tsffs.h"
#else
#ifdef __i386__
#include "tsffs-gcc-x86.h"
#elif __x86_64__
#include "tsffs-gcc-x86_64.h"
#elif __riscv && !__LP64__
#include "tsffs-gcc-riscv32.h"
#elif __riscv && __LP64__
#include "tsffs-gcc-riscv64.h"
#elif __aarch64__
#include "tsffs-gcc-aarch64.h"
#elif __arm__
#include "tsffs-gcc-arm32.h"
#endif
#endif

#include <stddef.h>

int test_start() {
char buf[1024];
size_t size = 1024;
HARNESS_START(buf, &size);
return 0;
}

int test_start_with_maximum_size() {
char buf[1024];
size_t size = 1024;
HARNESS_START_WITH_MAXIMUM_SIZE(buf, size);
return 0;
}

int test_start_with_maximum_size_and_ptr() {
char buf[1024];
size_t size = 1024;
HARNESS_START_WITH_MAXIMUM_SIZE_AND_PTR(buf, &size, 1024);
return 0;
}

int test_stop() {
char buf[1024];
size_t size = 1024;
HARNESS_STOP();
return 0;
}

int test_assert() {
char buf[1024];
size_t size = 1024;
HARNESS_ASSERT();
return 0;
}

#ifndef __arm__
int test_start_index() {
char buf[1024];
size_t size = 1024;
HARNESS_START_INDEX(1, buf, &size);
return 0;
}

int test_start_with_maximum_size_index() {
char buf[1024];
size_t size = 1024;
HARNESS_START_WITH_MAXIMUM_SIZE_INDEX(2, buf, size);
return 0;
}

int test_start_with_maximum_size_and_ptr_index() {
char buf[1024];
size_t size = 1024;
HARNESS_START_WITH_MAXIMUM_SIZE_AND_PTR_INDEX(3, buf, &size, 1024);
return 0;
}

int test_stop_index() {
char buf[1024];
size_t size = 1024;
HARNESS_STOP_INDEX(4);
return 0;
}

int test_assert_index() {
char buf[1024];
size_t size = 1024;
HARNESS_ASSERT_INDEX(5);
return 0;
}

#endif
62 changes: 62 additions & 0 deletions harness/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# Compile test.c for each of x86, x86_64, riscv32, riscv64 architecture

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

set -e

"${SCRIPT_DIR}/build.sh"

rm -f "${SCRIPT_DIR}/test_x86_64-clang.o" || exit 0
rm -f "${SCRIPT_DIR}/test_x86-clang.o" || exit 0
rm -f "${SCRIPT_DIR}/test_riscv32-clang.o" || exit 0
rm -f "${SCRIPT_DIR}/test_riscv64-clang.o" || exit 0
rm -f "${SCRIPT_DIR}/test_x86_64-gcc.o" || exit 0
rm -f "${SCRIPT_DIR}/test_x86-gcc.o" || exit 0
rm -rf "${SCRIPT_DIR}/test_aarch64-clang.o" || exit 0
rm -rf "${SCRIPT_DIR}/test_arm32-clang.o" || exit 0
rm -f "${SCRIPT_DIR}/test_x86_64-clang-single-file.o" || exit 0
rm -f "${SCRIPT_DIR}/test_x86-clang-single-file.o" || exit 0
rm -f "${SCRIPT_DIR}/test_riscv32-clang-single-file.o" || exit 0
rm -f "${SCRIPT_DIR}/test_riscv64-clang-single-file.o" || exit 0
rm -f "${SCRIPT_DIR}/test_x86_64-gcc-single-file.o" || exit 0
rm -f "${SCRIPT_DIR}/test_x86-gcc-single-file.o" || exit 0
rm -rf "${SCRIPT_DIR}test_aarch64-clang-single-file.o" || exit 0
rm -rf "${SCRIPT_DIR}test_arm32-clang-single-file.o" || exit 0

echo "Testing x86_64 (single file)..."
clang -target x86_64-unknown-linux-gnu -DSINGLE_FILE=1 -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_x86_64-clang-single-file.o"
echo "Testing i386 (single file)..."
clang -target i386-unknown-linux-gnu -DSINGLE_FILE=1 -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_x86-clang-single-file.o"
echo "Testing riscv32 (single file)..."
clang -target riscv32-unknown-linux-gnu -DSINGLE_FILE=1 -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_riscv32-clang-single-file.o"
echo "Testing riscv64 (single file)..."
clang -target riscv64-unknown-linux-gnu -DSINGLE_FILE=1 -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_riscv64-clang-single-file.o"
echo "Testing aarch64 (single file)..."
clang -target aarch64-unknown-linux-gnu -DSINGLE_FILE=1 -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_aarch64-clang-single-file.o"
echo "Testing arm (single file)..."
clang -target arm-unknown-linux-gnu -mfloat-abi=soft -DSINGLE_FILE=1 -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_arm32-clang-single-file.o"
echo "Testing x86_64 (single file, gcc)..."
gcc -DSINGLE_FILE=1 -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_x86_64-gcc.o"
echo "Testing i386 (single file, gcc)..."
gcc -DSINGLE_FILE=1 -g -m32 -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_x86-gcc.o"
echo "Testing x86_64 (multi file)..."
clang -target x86_64-unknown-linux-gnu -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_x86_64-clang.o"
echo "Testing i386 (multi file)..."
clang -target i386-unknown-linux-gnu -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_x86-clang.o"
echo "Testing riscv32(multi file)..."
clang -target riscv32-unknown-linux-gnu -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_riscv32-clang.o"
echo "Testing riscv64(multi file)..."
clang -target riscv64-unknown-linux-gnu -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_riscv64-clang.o"
echo "Testing aarch64 (multi file)..."
clang -target aarch64-unknown-linux-gnu -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_aarch64-clang.o"
echo "Testing arm (multi file)..."
clang -target arm-unknown-linux-gnu -mfloat-abi=soft -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_arm32-clang.o"
echo "Testing x86_64 (multi file, gcc)..."
gcc -g -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_x86_64-gcc.o"
echo "Testing i386(multi file, gcc)..."
gcc -g -m32 -c "${SCRIPT_DIR}/test.c" -o "${SCRIPT_DIR}/test_x86-gcc.o"
Loading

0 comments on commit e14afdf

Please sign in to comment.