Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lava-testcases/compatibility-test/toolchain-smoke/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CC ?= gcc
CXX ?= g++
BUILD_DIR ?= build
CFLAGS ?= -Wall -Wextra
CXXFLAGS ?= -Wall -Wextra

.PHONY: all
all: $(BUILD_DIR)/hello_c_make $(BUILD_DIR)/hello_cpp_make

$(BUILD_DIR):
mkdir -p $@

$(BUILD_DIR)/hello_c_make: hello.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -o $@ $<

$(BUILD_DIR)/hello_cpp_make: hello.cpp | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -o $@ $<
7 changes: 7 additions & 0 deletions lava-testcases/compatibility-test/toolchain-smoke/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main(void)
{
puts("Hello from C");
return 0;
}
7 changes: 7 additions & 0 deletions lava-testcases/compatibility-test/toolchain-smoke/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <iostream>

int main()
{
std::cout << "Hello from C++" << std::endl;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

set -u
set -x

OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
BUILD_DIR="${OUTPUT}/build"
EXPECTED_ELF_MACHINE="${EXPECTED_ELF_MACHINE:-RISC-V}"

result() {
echo "$1 $2" | tee -a "${RESULT_FILE}"
}

rm -rf "${OUTPUT}"
mkdir -p "${OUTPUT}" "${BUILD_DIR}"
: > "${RESULT_FILE}"

yum install -y gcc gcc-c++ make binutils glibc-devel

for item in gcc:gcc gxx:g++ make:make readelf:readelf objdump:objdump; do
test_case="${item%%:*}"
tool="${item#*:}"
if command -v "${tool}" >/dev/null 2>&1; then
"${tool}" --version 2>&1 | head -n 1
result "toolchain-${test_case}-version" "pass"
else
result "toolchain-${test_case}-version" "fail"
fi
done

gcc -Wall -Wextra -o "${BUILD_DIR}/hello_c" hello.c
[ "$?" -eq 0 ] && result "toolchain-gcc-build-c" "pass" || result "toolchain-gcc-build-c" "fail"

if [ -x "${BUILD_DIR}/hello_c" ]; then
"${BUILD_DIR}/hello_c" | tee "${OUTPUT}/hello_c.log"
fi

if grep -Fxq "Hello from C" "${OUTPUT}/hello_c.log"; then
result "toolchain-run-c" "pass"
else
result "toolchain-run-c" "fail"
fi

g++ -Wall -Wextra -o "${BUILD_DIR}/hello_cpp" hello.cpp
[ "$?" -eq 0 ] && result "toolchain-gxx-build-cpp" "pass" || result "toolchain-gxx-build-cpp" "fail"

if [ -x "${BUILD_DIR}/hello_cpp" ]; then
"${BUILD_DIR}/hello_cpp" | tee "${OUTPUT}/hello_cpp.log"
fi

if grep -Fxq "Hello from C++" "${OUTPUT}/hello_cpp.log"; then
result "toolchain-run-cpp" "pass"
else
result "toolchain-run-cpp" "fail"
fi

make CC=gcc CXX=g++ BUILD_DIR="${BUILD_DIR}/make"
[ "$?" -eq 0 ] && result "toolchain-make-build" "pass" || result "toolchain-make-build" "fail"

if [ -x "${BUILD_DIR}/make/hello_cpp_make" ]; then
"${BUILD_DIR}/make/hello_cpp_make" | tee "${OUTPUT}/hello_cpp_make.log"
fi

if grep -Fxq "Hello from C++" "${OUTPUT}/hello_cpp_make.log"; then
result "toolchain-run-make" "pass"
else
result "toolchain-run-make" "fail"
fi

readelf -h "${BUILD_DIR}/hello_c" 2>&1 | tee "${OUTPUT}/readelf-header.log"
grep -Eq "Class:[[:space:]]+ELF64" "${OUTPUT}/readelf-header.log" \
&& result "toolchain-elf-class-64" "pass" \
|| result "toolchain-elf-class-64" "fail"

grep -F "Machine:" "${OUTPUT}/readelf-header.log" | grep -Fq "${EXPECTED_ELF_MACHINE}" \
&& result "toolchain-elf-machine" "pass" \
|| result "toolchain-elf-machine" "fail"

objdump -f "${BUILD_DIR}/hello_c" 2>&1 | tee "${OUTPUT}/objdump.log"
[ "${PIPESTATUS[0]}" -eq 0 ] && result "toolchain-objdump-readable" "pass" || result "toolchain-objdump-readable" "fail"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
metadata:
name: toolchain-smoke
format: "Lava-Test Test Definition 1.0"
description: "Run GCC/G++/make/binutils smoke tests on openEuler RISC-V"
maintainer:
- zhangtianyu@iscas.ac.cn
os:
- openEuler-riscv64
scope:
- compatibility
- toolchain
devices:
- qemu
- lpi4a
- sg2042
- spacemit-k1-bananapi-f3

run:
steps:
- cd lava-testcases/compatibility-test/toolchain-smoke/
- chmod +x toolchain-smoke.sh
- ./toolchain-smoke.sh
- chmod +x ../../utils/send-to-lava.sh
- ../../utils/send-to-lava.sh ./output/result.txt
Loading