Add basic test
This commit is contained in:
parent
880a5c5580
commit
a50bf8e1b0
3 changed files with 123 additions and 0 deletions
23
Sanity/basic-test/main.fmf
Normal file
23
Sanity/basic-test/main.fmf
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
summary: Basic test
|
||||
description: ''
|
||||
contact: František Hrdina <fhrdina@redhat.com>
|
||||
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
|
||||
36
Sanity/basic-test/test.sh
Executable file
36
Sanity/basic-test/test.sh
Executable file
|
|
@ -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
|
||||
64
Sanity/basic-test/test_libcpuid.c
Normal file
64
Sanity/basic-test/test_libcpuid.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libcpuid.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue