From a50bf8e1b0a05d976d6541eeab06d72d72a4a50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Hrdina?= Date: Mon, 29 Jul 2024 14:56:31 +0200 Subject: [PATCH] Add basic test --- Sanity/basic-test/main.fmf | 23 +++++++++++ Sanity/basic-test/test.sh | 36 +++++++++++++++++ Sanity/basic-test/test_libcpuid.c | 64 +++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 Sanity/basic-test/main.fmf create mode 100755 Sanity/basic-test/test.sh create mode 100644 Sanity/basic-test/test_libcpuid.c diff --git a/Sanity/basic-test/main.fmf b/Sanity/basic-test/main.fmf new file mode 100644 index 0000000..99da2ef --- /dev/null +++ b/Sanity/basic-test/main.fmf @@ -0,0 +1,23 @@ +summary: Basic test +description: '' +contact: FrantiĊĦek Hrdina +component: + - libcpuid +test: ./test.sh +framework: beakerlib +recommend: + - libcpuid + - libcpuid-devel + - gcc +duration: 5m +enabled: true +tag: + - Tier1 +tier: '1' +adjust: + - enabled: false + when: distro < rhel-10 + continue: false + - enabled: false + when: distro < centos-stream-10 + continue: false diff --git a/Sanity/basic-test/test.sh b/Sanity/basic-test/test.sh new file mode 100755 index 0000000..b9ccdce --- /dev/null +++ b/Sanity/basic-test/test.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm "libcpuid" + TestDir=$(pwd) + rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" + rlRun "pushd $tmp" + + rlIsRHEL && repos="--enablerepo=rhel-CRB --enablerepo=rhel-buildroot" + rlIsCentOS && repos="--enablerepo=crb" + rlIsRHELLike && rlRun "dnf install -y $(rlGetRecommended) $repos" + rlCheckDependencies + rlRun "gcc $TestDir/test_libcpuid.c -o test_libcpuid -I/usr/include/libcpuid -lcpuid" + rlAssertExists "./test_libcpuid" + rlPhaseEnd + + rlPhaseStartTest + rlRun "./test_libcpuid &> libcpuid.log" + rlAssertNotGrep "Error getting raw CPU data" libcpuid.log + rlAssertNotGrep "Error identifying CPU" libcpuid.log + rlAssertNotGrep "Error retrieving clock frequency" libcpuid.log + rlAssertNotGrep "Error: Vendor string is empty or NULL." libcpuid.log + rlAssertNotGrep "Error: Model string is empty or NULL" libcpuid.log + rlAssertNotGrep "Error: Number of cores is not greater than 0" libcpuid.log + rlAssertNotGrep "Error: Number of logical CPUs is not greater than 0" libcpuid.log + rlRun "cat libcpuid.log" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $tmp" 0 "Remove tmp directory" + rlPhaseEnd +rlJournalEnd diff --git a/Sanity/basic-test/test_libcpuid.c b/Sanity/basic-test/test_libcpuid.c new file mode 100644 index 0000000..34395fa --- /dev/null +++ b/Sanity/basic-test/test_libcpuid.c @@ -0,0 +1,64 @@ +#include +#include +#include + + +int main() { + struct cpu_raw_data_t raw; + struct cpu_id_t data; + double cpu_clock; + + // Get raw CPU data + if (cpuid_get_raw_data(&raw) < 0) { + fprintf(stderr, "Error getting raw CPU data: %s\n", cpuid_error()); + return 1; + } + + // Decode data + if (cpu_identify(&raw, &data) < 0) { + fprintf(stderr, "Error identifying CPU: %s\n", cpuid_error()); + return 1; + } + + // Get current clock frequency + cpu_clock = cpu_clock_by_os(); + if (cpu_clock < 0) { + fprintf(stderr, "Error retrieving clock frequency: %s\n", cpuid_error()); + return 1; + } + + // Check if vendor and model are non-empty strings + if (data.vendor_str == NULL || strlen(data.vendor_str) == 0) { + fprintf(stderr, "Error: Vendor string is empty or NULL.\n"); + return 1; + } + + if (data.brand_str == NULL || strlen(data.brand_str) == 0) { + fprintf(stderr, "Error: Model string is empty or NULL.\n"); + return 1; + } + + + if (data.num_cores <= 0) { + fprintf(stderr, "Error: Number of cores is not greater than 0.\n"); + return 1; + } + + if (data.num_logical_cpus <= 0) { + fprintf(stderr, "Error: Number of logical CPUs is not greater than 0.\n"); + return 1; + } + + // Print basic CPU information + printf("Vendor: %s\n", data.vendor_str); + printf("Model: %s\n", data.brand_str); + printf("Family: %d\n", data.family); + printf("Model: %d\n", data.model); + printf("Stepping: %d\n", data.stepping); + printf("Current clock frequency: %.2f MHz\n", cpu_clock); + printf("Cores: %d\n", data.num_cores); + printf("Logical CPUs: %d\n", data.num_logical_cpus); + + return 0; +} +