shell脚本调用c语言测试用例

一、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
 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值