Skip to content

Commit

Permalink
Add 8 telemetry cases
Browse files Browse the repository at this point in the history
check if telemetry sysfs is generated
check if telemetry device is generated
check if detailed telemetry sysfs value is correct
check if telemetry data is readable
check if pci drvier loaded
check load/unload telemetry drvier
check load/unload telemetry pci drvier with 32bit binary
check load/unload telemetry pci drvier

Signed-off-by: Ammy Yi <[email protected]>
  • Loading branch information
ammyyi committed Feb 21, 2024
1 parent f71c222 commit 152a52b
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 0 deletions.
2 changes: 2 additions & 0 deletions telemetry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/telemetry_tests
/telemetry_tests_32
10 changes: 10 additions & 0 deletions telemetry/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2022 Intel Corporation.

all:
gcc telemetry_tests.c -m64 -o telemetry_tests
gcc telemetry_tests.c -m32 -o telemetry_tests_32

clean:
rm -rf telemetry_tests
rm -rf telemetry_tests_32
22 changes: 22 additions & 0 deletions telemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Telemetry is collected and returned regardless of its type. For example, telemetry will include counters, sampled data (such as voltages) and more complex data (such as histograms).
Collecting and reporting telemetry allows for a more detailed understanding of the operation of the system from which the telemetry is obtained.

Current test cases are focusing on telemetry Aggregator

Detailed cases:
#check if telemetry sysfs is generated
telemetry_tests.sh -t telem_sysfs
#check if telemetry device is generated
telemetry_tests.sh -t telem_dev
#check if detailed telemetry sysfs value is correct
telemetry_tests.sh -t telem_sysfs_common
#check if telemetry data is readable
telemetry_tests.sh -t telem_data
#check if pci drvier loaded
telemetry_tests.sh -t pci
#check load/unload telemetry drvier
telemetry_tests.sh -t telem_driver
#check load/unload telemetry pci drvier with 32bit binary
telemetry_tests.sh -t telem_data_32
#check load/unload telemetry pci drvier
telemetry_tests.sh -t pci_driver
86 changes: 86 additions & 0 deletions telemetry/telemetry_tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: GPL-2.0-or-later

/*
* Author: Ammy Yi ([email protected])
*/

/*
* This test will check if telemetry is working.
*/

#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>

#define SAMPLE_SIZE 8

void print_bin(uint8_t n)
{
uint8_t l = sizeof(n)*8;
int i;
for(i = l-1;i>=0; i --)
printf("%d", (n&(1<<i)) != 0);
}

int telem_test(char *telem_dev, int size, int idx)
{
int offset = idx * getpagesize();
char *ptr;
int fd;
int i = 0;
fd = open(telem_dev, O_RDONLY);
if (fd == -1)
{
printf("open telem device failure with %s!\n", telem_dev);
return -1;
}
#if 0
//mmap is not supported with latest kernel!
ptr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, offset);
#endif
ptr=(char*)malloc(SAMPLE_SIZE*size*sizeof(char));
read(fd, ptr, SAMPLE_SIZE*size);
for (i = size; i >= 0; i--)
{
printf("telem value 0x%x= ", i);
print_bin(ptr[i]);
printf("\n");
}
free(ptr);
#if 0
munmap(ptr, size);
#endif
close(fd);
return 0;
}

int main(int argc,char *argv[])
{
int result = 2;
int cmd;
char *dev;
int size, idx;
if (argc==5)
{
cmd = atoi(argv[1]);
dev = argv[2];
size = atoi(argv[3]);
idx = atoi(argv[4]);
printf("cmd = %d, dev = %s, size = %d, idx = %d\n", cmd, dev, size, idx);
}
switch (cmd) {
case 1:
result=telem_test(dev, size, idx);
break;
default:
printf("Command is not correct!\n");
break;
}
printf("CASE result = %d \n", result);
return result;
}
152 changes: 152 additions & 0 deletions telemetry/telemetry_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Author:
# Ammy Yi <[email protected]>
#
# History:
# Feb. 2, 2024 - (Ammy Yi)Creation


# @desc This script verify telemetry test
# @returns Fail the test if return code is non-zero (value set not found)


cd "$(dirname "$0")" 2>/dev/null || exit 1
source ../.env

: ${CASE_NAME:=""}

usage() {
cat <<__EOF
usage: ./${0##*/} [-t TESTCASE_ID] [-H]
-t TEST CASE ID
-H show this
__EOF
}

SYSFS_PATH="/sys/class/intel_pmt"

telem_sysfs_test() {
do_cmd "ls $SYSFS_PATH | grep telem"
}

telem_dev_test() {
do_cmd "ls $SYSFS_PATH | grep telem"
}

telem_sysfs_common_test() {
ids=$(ls $SYSFS_PATH | grep telem)
[[ -z $ids ]] && die "No telemetry device found!"
for id in $ids; do
do_cmd "cat $SYSFS_PATH/$id/guid"
do_cmd "cat $SYSFS_PATH/$id/size"
do_cmd "ls $SYSFS_PATH/$id | grep device"
should_fail "echo 0 > $SYSFS_PATH/$id/guid"
should_fail "echo 0 > $SYSFS_PATH/$id/size"
done
}

telem_data_test() {
offset=$1
bin=$2
tel_bin="telemetry_tests"
[[ $bin -eq 32 ]] && tel_bin="telemetry_tests_32"
ids=$(ls $SYSFS_PATH | grep telem)
[[ -z $ids ]] && die "No telemetry device found!"
test_print_trc "ids=$ids!"
for id in $ids; do
test_print_trc "id=$id!"
size=$(cat "$SYSFS_PATH"/"$id"/size)
let size=size-1
do_cmd "ls $SYSFS_PATH/$id/telem"
do_cmd "$tel_bin 1 $SYSFS_PATH/$id/telem $size $offset"
done
}

pci_test() {
do_cmd "lspci -knnv | grep -c intel_vsec"
}

pre_unload_driver() {
rmmod intel_pmc_core
rmmod intel_tpmi_pem
rmmod intel_tpmi_pem_core
rmmod intel_rapl_tpmi
rmmod isst_tpmi
rmmod isst_tpmi_core
rmmod intel_uncore_frequency_tpmi
rmmod intel_vsec_tpmi
}

driver_test() {
module=$1
pre_unload_driver
load_unload_module.sh -c -d "$module" && \
do_cmd "load_unload_module.sh -u -d $module"
do_cmd "load_unload_module.sh -l -d $module"
sleep 5
pre_unload_driver
do_cmd "load_unload_module.sh -u -d $module"
do_cmd "load_unload_module.sh -l -d $module"
}

dmesg_check() {
should_fail "extract_case_dmesg | grep BUG"
should_fail "extract_case_dmesg | grep 'Call Trace'"
should_fail "extract_case_dmesg | grep error"
}

telemetry_test() {
case $TEST_SCENARIO in
telem_sysfs)
telem_sysfs_test
;;
telem_dev)
telem_dev_test
;;
telem_sysfs_common)
telem_sysfs_common_test
;;
telem_data)
telem_data_test 0
;;
pci)
pci_test
;;
telem_driver)
driver_test "pmt_telemetry"
;;
telem_data_32)
telem_data_test 0 32
;;
pci_driver)
driver_test "intel_vsec"
;;
esac
dmesg_check
return 0
}

while getopts :t:w:H arg; do
case $arg in
t)
TEST_SCENARIO=$OPTARG
;;
H)
usage && exit 0
;;
\?)
usage
die "Invalid Option -$OPTARG"
;;
:)
usage
die "Option -$OPTARG requires an argument."
;;
esac
done

telemetry_test
# Call teardown for passing case
exec_teardown
9 changes: 9 additions & 0 deletions telemetry/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file collects the telemetry cases
telemetry_tests.sh -t pci
telemetry_tests.sh -t pci_driver
telemetry_tests.sh -t telem_driver
telemetry_tests.sh -t telem_sysfs
telemetry_tests.sh -t telem_dev
telemetry_tests.sh -t telem_sysfs_common
telemetry_tests.sh -t telem_data
telemetry_tests.sh -t telem_data_32

0 comments on commit 152a52b

Please sign in to comment.