RTXI 1.3
comedilib/testing/main.c
Go to the documentation of this file.
00001 /*
00002  */
00003 
00004 #include <stdio.h>
00005 #include <comedilib.h>
00006 #include <fcntl.h>
00007 #include <unistd.h>
00008 #include <stdlib.h>
00009 #include <sys/ioctl.h>
00010 #include <errno.h>
00011 #include <getopt.h>
00012 #include <ctype.h>
00013 #include <malloc.h>
00014 #include <string.h>
00015 
00016 #include "comedi_test.h"
00017 
00018 char *filename="/dev/comedi0";
00019 int verbose_flag;
00020 comedi_t *device;
00021 
00022 int subdevice;
00023 int channel;
00024 int aref;
00025 int range;
00026 
00027 int test_info(void);
00028 int test_mode0_read(void);
00029 int test_insn_read(void);
00030 int test_insn_read_0(void);
00031 int test_insn_read_time(void);
00032 int test_cmd_no_cmd(void);
00033 int test_cmd_probe_src_mask(void);
00034 int test_cmd_probe_fast_1chan(void);
00035 int test_cmd_read_fast_1chan(void);
00036 int test_cmd_write_fast_1chan(void);
00037 int test_cmd_logic_bug(void);
00038 int test_cmd_fifo_depth_check(void);
00039 int test_cmd_start_inttrig(void);
00040 int test_mmap(void);
00041 int test_read_select(void);
00042 int test_cmd_continuous(void);
00043 int test_bufconfig(void);
00044 
00045 #define TEST_NEVER 0
00046 #define TEST_STD 1
00047 
00048 struct test_struct{
00049         char *name;
00050         int (*do_test)(void);
00051         int flags;
00052 };
00053 struct test_struct tests[]={
00054         { "info", test_info, TEST_STD },
00055         { "mode0_read", test_mode0_read, TEST_NEVER },
00056         { "insn_read", test_insn_read, TEST_STD },
00057         { "insn_read_0", test_insn_read_0, TEST_STD },
00058         { "insn_read_time", test_insn_read_time, TEST_STD },
00059         { "cmd_no_cmd", test_cmd_no_cmd, TEST_STD },
00060         { "cmd_probe_src_mask", test_cmd_probe_src_mask, TEST_STD },
00061         { "cmd_probe_fast_1chan", test_cmd_probe_fast_1chan, TEST_STD },
00062         { "cmd_read_fast_1chan", test_cmd_read_fast_1chan, TEST_STD },
00063         { "cmd_write_fast_1chan", test_cmd_write_fast_1chan, TEST_STD },
00064         { "cmd_logic_bug", test_cmd_logic_bug, TEST_STD },
00065         { "cmd_fifo_depth_check", test_cmd_fifo_depth_check, TEST_STD },
00066         { "cmd_start_inttrig", test_cmd_start_inttrig, TEST_STD },
00067         { "mmap", test_mmap, TEST_STD },
00068         { "read_select", test_read_select, TEST_STD },
00069         { "cmd_continuous", test_cmd_continuous, TEST_NEVER },
00070         { "bufconfig", test_bufconfig, TEST_STD },
00071 };
00072 static int n_tests = sizeof(tests)/sizeof(tests[0]);
00073 
00074 int only_subdevice;
00075 int verbose;
00076 char *only_test;
00077 int realtime;
00078 
00079 static void get_capabilities(unsigned int subd);
00080 static void print_device_info(void);
00081 
00082 void help(int ret)
00083 {
00084         int i;
00085 
00086         fprintf(stderr,
00087 "comedi_test [options]\n"
00088 "  --device, -f <device_file>   Use device <device_file>\n"
00089 "  --realtime, -r               Use real-time interrupts, if available\n"
00090 "  --subdevice, -s <index>      Only test subdevice <index>\n"
00091 "  --test, -t <test>            Only run test <test>\n"
00092 "  --verbose, -v                Be verbose\n"
00093 "  --help, -h                   Print this message\n"
00094 "Available tests: ");
00095         for(i=0;i<n_tests;i++){
00096                 fprintf(stderr,"%s ",tests[i].name);
00097         }
00098         fprintf(stderr,"\n");
00099 
00100         exit(ret);
00101 }
00102 
00103 static struct option longopts[]={
00104         { "device", 1, 0, 'f' },
00105         { "realtime", 0, 0, 'r' },
00106         { "subdevice", 1, 0, 's' },
00107         { "test", 1, 0, 't' },
00108         { "verbose", 0, 0, 'v' },
00109         { "help", 0, 0, 'h' },
00110         {0}
00111 };
00112 
00113 int main(int argc, char *argv[])
00114 {
00115         int c;
00116         int i;
00117 
00118         setvbuf(stdout,NULL,_IONBF,0);
00119 
00120         while (1) {
00121                 c = getopt_long(argc, argv, "f:rs:t:v", longopts, NULL);
00122                 if (c == -1)
00123                         break;
00124                 switch (c) {
00125                 case 'f':
00126                         filename = optarg;
00127                         break;
00128                 case 'r':
00129                         realtime = 1;
00130                         break;
00131                 case 's':
00132                         only_subdevice = 1;
00133                         sscanf(optarg,"%d",&subdevice);
00134                         break;
00135                 case 't':
00136                         only_test = optarg;
00137                         break;
00138                 case 'h':
00139                         help(0);
00140                         break;
00141                 case 'v':
00142                         verbose = 1;
00143                         break;
00144                 default:
00145                         help(1);
00146                         break;
00147                 }
00148         }
00149 
00150         device = comedi_open(filename);
00151         if(!device){
00152                 printf("E: comedi_open(\"%s\"): %s\n",filename,strerror(errno));
00153                 exit(1);
00154         }
00155 
00156         print_device_info();
00157 
00158         for(;subdevice<comedi_get_n_subdevices(device);subdevice++){
00159                 printf("I:\n");
00160                 printf("I: subdevice %d\n",subdevice);
00161                 get_capabilities(subdevice);
00162                 if(only_test){
00163                         for(i=0;i<n_tests;i++){
00164                                 if(!strcmp(tests[i].name,only_test)){
00165                                         printf("I: testing %s...\n",tests[i].name);
00166                                         tests[i].do_test();
00167                                 }
00168                         }
00169                 }else{
00170                         for(i=0;i<n_tests;i++){
00171                                 if(tests[i].flags&TEST_STD){
00172                                         printf("I: testing %s...\n",tests[i].name);
00173                                         tests[i].do_test();
00174                                 }
00175                         }
00176                 }
00177                 if(only_subdevice)break;
00178         }
00179 
00180         return 0;
00181 }
00182 
00183 unsigned int capabilities;
00184 
00185 static void get_capabilities(unsigned int subd)
00186 {
00187         int type;
00188         int flags;
00189 
00190         capabilities = 0;
00191 
00192         type = comedi_get_subdevice_type(device,subd);
00193 
00194         flags = comedi_get_subdevice_flags(device,subd);
00195 
00196 }
00197 
00198 static void print_device_info(void)
00199 {
00200         int vers = comedi_get_version_code(device);
00201 
00202         printf("I: Comedi version: %d.%d.%d\n",(vers>>16)&0xff,
00203                 (vers>>8)&0xff,vers&0xff);
00204         printf("I: Comedilib version: unknown =)\n");
00205         printf("I: driver name: %s\n",comedi_get_driver_name(device));
00206         printf("I: device name: %s\n",comedi_get_board_name(device));
00207 }
00208 
00209 
00210 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines