LLC2_API
|
00001 /* ------------------------------------------------------------------------- */ 00002 /* file testharness.h */ 00003 /* ------------------------------------------------------------------------- */ 00004 /* Copyright (C) 2011 Peter Milne, D-TACQ Solutions Ltd 00005 * <Peter dot Milne at D hyphen TACQ dot com> 00006 * Created on: Sep 25, 2011 00007 * Author: pgm 00008 00009 http://www.d-tacq.com 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of Version 2 of the GNU General Public License 00013 as published by the Free Software Foundation; 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 00023 /* ------------------------------------------------------------------------- */ 00024 00025 /** @file testharness.h - test harness Outputs, Inputs. 00026 * 00027 */ 00028 00029 #ifndef TESTHARNESS_H_ 00030 #define TESTHARNESS_H_ 00031 00032 00033 00034 class Outputs { 00035 /**< Outputs: testharness example outputs. */ 00036 const int ao_count; 00037 int ao_len; 00038 short* ao_buf; 00039 unsigned long long do_buf[2]; 00040 00041 public: 00042 short *getAO(int ii) { 00043 int offset = (ii*ao_count)%ao_len; 00044 00045 return ao_buf+offset; 00046 } 00047 /** re-uses same set of 32 DO, two values. */ 00048 unsigned *getDO(int ii){ 00049 return (unsigned*)&do_buf[ii&1]; 00050 } 00051 00052 00053 Outputs(int _ao_count = 32, int do_count = 32) : 00054 ao_count(_ao_count) 00055 { 00056 const char* aofn; 00057 if ((aofn = getenv("LL_OUTPUTS")) != 0){ 00058 struct stat buf; 00059 int rc; 00060 00061 rc = stat(aofn, &buf); 00062 if (rc == 0){ 00063 ao_len = buf.st_size/sizeof(short); 00064 ao_buf = new short [ao_len]; 00065 FILE *fp = fopen(aofn, "r"); 00066 assert(fp); 00067 fread(ao_buf, ao_len, sizeof(short), fp); 00068 fclose(fp); 00069 }else{ 00070 perror(aofn); 00071 exit(errno); 00072 } 00073 }else{ 00074 ao_len = ao_count; 00075 ao_buf = new short[ao_len]; 00076 for (int ii = 0; ii != ao_count; ++ii){ 00077 ao_buf[ii] = 500*ii; 00078 } 00079 } 00080 00081 do_buf[0] = 0ULL; 00082 do_buf[1] = ~0ULL; 00083 } 00084 00085 ~Outputs() { 00086 delete [] ao_buf; 00087 } 00088 }; 00089 00090 class Inputs { 00091 const int samples; 00092 const int ai_count; 00093 const int di_count; 00094 const int status_count; 00095 short *ai; 00096 unsigned *di; 00097 unsigned *status; 00098 00099 static void writeFile(const char* fname, void* buf, int nbytes){ 00100 FILE *fp = fopen(fname, "w"); 00101 assert(fp); 00102 fwrite(buf, nbytes, 1, fp); 00103 fclose(fp); 00104 } 00105 public: 00106 short *getAI(int ii){ 00107 return ai + ii*ai_count; 00108 } 00109 unsigned *getDI(int ii){ 00110 return di + ii*di_count/32; 00111 } 00112 unsigned *getStatus(int ii){ 00113 return status+ii*status_count; 00114 } 00115 Inputs(int _samples, int _ai_count = 96, int _di_count = 32, 00116 int _status_count = 16) : 00117 samples(_samples), 00118 ai_count(_ai_count), 00119 di_count(_di_count), 00120 status_count(_status_count) 00121 00122 { 00123 ai = znew<short>(samples*ai_count); 00124 di = znew<unsigned>(samples*di_count/BITS_PER_DX_WORD); 00125 status = znew<unsigned>(samples*status_count); 00126 } 00127 ~Inputs() 00128 { 00129 writeFile("ai.dat", ai, samples*ai_count*sizeof(short)); 00130 writeFile("di.dat", di, samples*di_count/BITS_PER_DX_WORD*sizeof(unsigned)); 00131 writeFile("status.dat", status, samples*status_count*sizeof(unsigned)); 00132 00133 delete [] ai; 00134 delete [] di; 00135 delete [] status; 00136 } 00137 }; 00138 00139 00140 #endif /* TESTHARNESS_H_ */