From e85f43e8c2f164789bb1c0fcae384e4d40a3a0a2 Mon Sep 17 00:00:00 2001 From: Bade Appala Naidu Date: Thu, 17 May 2012 15:26:06 +0530 Subject: Added Gyroscope pressure Acceleormetr and Proximity sensor testcases Added snowball specific cmmand file --- kernel/testcases/l3g4200d/Makefile | 21 +++ kernel/testcases/l3g4200d/sensor_l3g4200d.c | 254 ++++++++++++++++++++++++++++ 2 files changed, 275 insertions(+) create mode 100644 kernel/testcases/l3g4200d/Makefile create mode 100644 kernel/testcases/l3g4200d/sensor_l3g4200d.c (limited to 'kernel/testcases/l3g4200d') diff --git a/kernel/testcases/l3g4200d/Makefile b/kernel/testcases/l3g4200d/Makefile new file mode 100644 index 0000000..6e128bc --- /dev/null +++ b/kernel/testcases/l3g4200d/Makefile @@ -0,0 +1,21 @@ +ifeq ($(KERNELRELEASE),) +LTP_DIR = $(abspath ../../../) +LTP_FULL = $(LTP_DIR)/tempdir/ltp-full + +CFLAGS+= -I$(LTP_FULL)/include -I./include +LOADLIBES+= -L$(LTP_FULL)/lib -lltp + +SRCS=$(wildcard *.c) +TARGETS=$(patsubst %.c,%,$(SRCS)) + +all: $(TARGETS) + +install: + @for i in $(TARGETS); do if [ -f $(DESTDIR)/opt/ltp/testcases/bin/$$i ]; then rm $(DESTDIR)/opt/ltp/testcases/bin/$$i; fi ; done + @for i in $(TARGETS); do install $$i $(DESTDIR)/opt/ltp/testcases/bin/$$i ; done + @for i in $(SCRIPTS); do if [ -f $(DESTDIR)/opt/ltp/testcases/bin/$$i ]; then rm $(DESTDIR)/opt/ltp/testcases/bin/$$i; fi ; done + @for i in $(SCRIPTS); do install $$i $(DESTDIR)/opt/ltp/testcases/bin/$$i ; done + +clean: + rm -f $(TARGETS) +endif diff --git a/kernel/testcases/l3g4200d/sensor_l3g4200d.c b/kernel/testcases/l3g4200d/sensor_l3g4200d.c new file mode 100644 index 0000000..30f50b1 --- /dev/null +++ b/kernel/testcases/l3g4200d/sensor_l3g4200d.c @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2011 ST-Ericsson + * License terms: GNU General Public License (GPL) version 2 + * + * Author: 2011, Chethan Krishna N + */ + + +/******************************************************************************/ +/* Description: Test x, y and z axis values from gyroscope driver. +/* +/* Test Assertion and Strategy: Assert if all three axes data is valid. +/* +/******************************************************************************/ + +/* Harness Specific Include Files. */ +#include "test.h" +#include "usctest.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* Extern Global Variables */ +extern int Tst_count; /* counter for tst_xxx routines. */ +extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */ + +/* Global Variables */ +char *TCID = "l3g4200d"; /* test program identifier. */ + +/* total number of tests in this file. */ +int TST_TOTAL = 1; + +#define INVALID_DATA_READ -1 +#define VALID_DATA 0 + +char *gyr_filepath = "/sys/devices/platform/nmk-i2c.2/i2c-2/2-0068/gyrodata"; +char *gyr_filepath_activate = "/sys/devices/platform/nmk-i2c.2/i2c-2/2-0068/powermode"; +char *gyr_filepath_range = "/sys/devices/platform/nmk-i2c.2/i2c-2/2-0068/range"; +char *gyr_filepath_rate = "/sys/devices/platform/nmk-i2c.2/i2c-2/2-0068/datarate"; +char *gyr_filepath_temp = "/sys/devices/platform/nmk-i2c.2/i2c-2/2-0068/gyrotemp"; + +int gyr_set_properties() +{ + FILE *f; + unsigned long val = -1; + + f = fopen(gyr_filepath_rate, "w"); + if (f == NULL) + return -1; + + if (fputc((int)'0', f) == EOF) + val = EOF; + else + val = 0; + + fclose(f); + + f = fopen(gyr_filepath_range, "w"); + if (f == NULL) + return -1; + + if (fputc((int)'0', f) ==EOF) + val = EOF; + else + val = 0; + + fclose(f); + + return val; +} + +int get_val(char *fname) +{ + FILE *f; + int data[3], ret; + + f = fopen(fname, "r"); + if (f == NULL) + return -1; + + if (fscanf(f, "%8x:%8x:%8x", &data[0], &data[1], &data[2]) != 3) + ret = INVALID_DATA_READ; + else + ret = VALID_DATA; + + fclose(f); + return ret; +} + +int gyr_get_properties() +{ + FILE *f; + int data; + int ret = 4; + + /* read powermode */ + f = fopen(gyr_filepath_activate, "r"); + if (f == NULL) + return -1; + + if (fscanf(f, "%d", &data) != 1) + goto error; + else + ret--; + fclose(f); + + /* read range */ + f = fopen(gyr_filepath_range, "r"); + if (f == NULL) + return -1; + + if (fscanf(f, "%d", &data) != 1) + goto error; + else + ret--; + fclose(f); + + /* show datarate */ + f = fopen(gyr_filepath_rate, "r"); + if (f == NULL) + return -1; + + if (fscanf(f, "%d", &data) != 1) + goto error; + else + ret--; + fclose(f); + + /* show gyrotemp */ + f = fopen(gyr_filepath_temp, "r"); + if (f == NULL) + return -1; + + if (fscanf(f, "%d", &data) != 1) + goto error; + else + ret--; + fclose(f); + + error: + fclose(f); + + return ret; +} + +int set_val() +{ + FILE *f; + unsigned long val = -1; + + /* Before acrivating device try writting to rate, + * range & read value to cover error cases. + */ + gyr_set_properties(); + /*Read output data value */ + get_val(gyr_filepath); + + f = fopen(gyr_filepath_activate, "w"); + if (f == NULL) + return -1; + + /* Activate L3G4200D device */ + if (fputc((int)'1', f) == EOF) + val = EOF; + else + val = 0; + + fclose(f); + return val; +} + +int main(int argc, const char **argv) +{ + + int lc; /* loop counter */ + char *msg; /* message returned from parse_opts */ + + /*************************************************************** + * parse standard options + ***************************************************************/ + if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL)) != (char *) NULL) { + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + tst_exit(); + } + + /*************************************************************** + * check looping state if -c option given + ***************************************************************/ + for (lc = 0; TEST_LOOPING(lc); lc++) { + + /*************************************************************** + * only perform functional verification if flag set (-f not given) + ***************************************************************/ + if (STD_FUNCTIONAL_TEST) { + + for (Tst_count = 0; Tst_count < TST_TOTAL;) { + + switch (Tst_count) { + case 0: + TEST(set_val()); + if (TEST_RETURN == 0) + tst_resm(TPASS, "Functional test %d OK\n", Tst_count); + else if (TEST_RETURN == EOF) + tst_resm(TFAIL, "Functional test %d failed. Error when activating gyroscope," + "confirm hardware presence TCID: %s File: %s", Tst_count, TCID, __FILE__); + else + tst_resm(TFAIL, "Functional test %d failed. FilePath: %s not found. TCID: %s File: %s\n" + , Tst_count, gyr_filepath_activate, TCID, __FILE__); + + TEST(gyr_set_properties()); + if (TEST_RETURN == 0) + tst_resm(TPASS, "Functional test %d OK\n", Tst_count); + else if (TEST_RETURN == EOF) + tst_resm(TFAIL, "Functional test %d failed. Error setting gyroscope properties," + "TCID: %s File: %s", Tst_count, TCID, __FILE__); + else + tst_resm(TFAIL, "Functional test %d failed. TCID: %s File: %s\n", Tst_count, TCID, __FILE__); + + TEST(get_val(gyr_filepath)); + if (TEST_RETURN == 0) + tst_resm(TPASS, "Functional test %d OK\n", Tst_count); + else if (TEST_RETURN == INVALID_DATA_READ) { + tst_resm(TFAIL, "Functional test %d failed. XYZ values not read completely" + "TCID: %s File: %s", Tst_count, TCID, __FILE__); + } else { + tst_resm(TFAIL, "Functional test %d failed. Filepath: %s not found. TCID: %s File: %s\n" + , Tst_count, gyr_filepath, TCID, __FILE__); + } + + TEST(gyr_get_properties()); + if (TEST_RETURN == 0) + tst_resm(TPASS, "Functional test %d OK\n", Tst_count); + else if (TEST_RETURN > 0) { + tst_resm(TFAIL, "Functional test %d failed. gyro property values not read completely" + "TCID: %s File: %s", Tst_count, TCID, __FILE__); + } else { + tst_resm(TFAIL, "Functional test %d failed. TCID: %s File: %s\n", Tst_count, TCID, __FILE__); + } + break; + } + } + } + tst_exit(); + return 0; + } +} -- cgit v1.2.3