一、c测试用例——按键的检测
#include <stdio.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "include/types.h"
__s32 main(__s32 argc, char **argv)
{
__s32 ret = 0, count = 0;
__s32 fd;
struct input_event ev;
fd = open(argv[1], O_RDONLY|O_NONBLOCK);
if (fd < 0) {
printf("open the input devices err!!!\n");
return 1;
}
printf("plese pull down the power key!\n");
printf("waiting 15s...\n");
fflush(NULL); //为了打印的都能显示在屏幕
while ( count < 15) {
ret = read(fd, &ev, sizeof(struct input_event));
if (ret <= 0) {
printf("plese pull down power key!\n");
fflush(NULL); //为了打印的都能显示在屏幕
// return 1;
} else {
printf("power key success!\n");
return 0;
}
count ++;
sleep(1);
}
printf("read event error, power key fail!\n");
return 1;
}
二、shell脚本的编写
#!/bin/sh
cd ../common
sh start_test.sh pmu pmu_key_test_function
cd ../pmu
#./pmu_key_test_function_common.sh
col_num=$(cat /proc/bus/input/devices | grep -n "axp" \
| sed '/i2c/d' | awk -F ":" '{print $1}')
hang_num=`expr $col_num + 4`
event=$(cat /proc/bus/input/devices | sed -n "${hang_num}p" | awk '{print $NF}') #为了获得powerkey的event
echo "$event"
if [ $event ]
then
./power_key_test "/dev/input/$event"
ret=$?
if [ $ret -eq 0 ];then
result="pass"
note=1
fi
if [ $ret -ne 0 ];then
result="fail"
note=1
fi
else
result="fail"
note=1
fi
cd ../common
sh end_test.sh pmu pmu_key_test_function $result
cd ../pmu