19 const int baud = 460800;
21 const int ctspin = 20;
22 const int rtspin = 21;
24 const int MAXTIME = 10;
31 static void setUp(
void) {
32 sut.Start(rxpin, txpin, baud);
35 static void tearDown(
void) {
41 static void test_PinsConnected(
void) {
46 DIRA &= ~(1 << ctspin);
49 TEST_ASSERT_TRUE((
INA & (1 << ctspin)) != 0);
51 OUTA &= ~(1 << rtspin);
52 TEST_ASSERT_TRUE((
INA & (1 << ctspin)) == 0);
57 DIRA &= ~(1 << rxpin);
60 TEST_ASSERT_TRUE((
INA & (1 << rxpin)) != 0);
62 OUTA &= ~(1 << txpin);
63 TEST_ASSERT_TRUE((
INA & (1 << rxpin)) == 0);
66 static void test_Start(
void) {
68 int32_t result = sut.Start(rxpin, txpin, baud);
69 TEST_ASSERT_TRUE(result);
72 static void test_SetsPinDirectionsCorrectly(
void) {
77 DIRA &= ~(1 << txpin);
79 sut.Start(rxpin, txpin, baud);
81 const char value =
'A';
83 TEST_ASSERT_EQUAL_INT(value, sut.Get(MAXTIME));
86 static void cog_DoNothing(
void * arg) {
90 static int help_CountNumberOfFreeCogs(
void) {
92 int * cog_stack = (
int*) malloc(stacksize);
93 int cog_id =
cogstart(cog_DoNothing, NULL, cog_stack, stacksize);
98 free_cogs = help_CountNumberOfFreeCogs() + 1;
107 static void test_StopStopsCog(
void) {
108 int beforeCount = help_CountNumberOfFreeCogs();
110 TEST_ASSERT_EQUAL_INT(beforeCount + 1, help_CountNumberOfFreeCogs());
131 static void test_PutCGetC(
void) {
133 TEST_ASSERT_EQUAL_INT(
'a', sut.Get(MAXTIME));
136 static void test_PutCGetCLowerByteBound(
void) {
138 TEST_ASSERT_EQUAL_INT(0, sut.Get(MAXTIME));
141 static void test_PutCGetCUpperByteBound(
void) {
143 TEST_ASSERT_EQUAL_INT(255, sut.Get(MAXTIME));
146 static void test_GetCCheckNoPutC(
void) {
147 TEST_ASSERT_EQUAL_INT(-1, sut.Get(MAXTIME));
150 static void test_GetCCheck(
void) {
152 TEST_ASSERT_EQUAL_INT(
'G', sut.Get(MAXTIME));
155 static void test_GetCCheckNoWait(
void) {
157 TEST_ASSERT_EQUAL_INT(
'T', sut.Get(1));
160 static void test_GetCCheckTimeTimeout(
void) {
161 TEST_ASSERT_EQUAL_INT(-1, sut.Get(1));
164 static void test_GetCValidateTimeoutDuration(
void) {
166 const int kTimeoutDuration = 10 * 1000;
167 const int kMaximumTimeoutDelta = 100;
169 for (
int i = 0; i < 10; i++) {
170 unsigned int start_CNT =
CNT;
171 sut.Get(kTimeoutDuration / 1000);
172 unsigned int actual_timeout_duration = (
CNT - start_CNT) / (
CLKFREQ / 1000000);
173 TEST_ASSERT_INT_WITHIN(kMaximumTimeoutDelta, kTimeoutDuration, actual_timeout_duration);
179 static void test_RxTxNoExtraTxChars(
void) {
182 TEST_ASSERT_EQUAL_INT(-1, sut.Get(MAXTIME));
189 static void test_PutBufferNoPointer(
void) {
190 TEST_ASSERT_EQUAL_INT(0, sut.PutFormatted((
char *) NULL));
191 TEST_ASSERT_EQUAL_INT(-1, sut.Get(MAXTIME));
194 static void test_PutS(
void) {
195 TEST_ASSERT_EQUAL_INT(5, sut.PutFormatted(
"Hello"));
196 TEST_ASSERT_EQUAL_INT(
'H', sut.Get(MAXTIME));
197 TEST_ASSERT_EQUAL_INT(
'e', sut.Get(MAXTIME));
198 TEST_ASSERT_EQUAL_INT(
'l', sut.Get(MAXTIME));
199 TEST_ASSERT_EQUAL_INT(
'l', sut.Get(MAXTIME));
200 TEST_ASSERT_EQUAL_INT(
'o', sut.Get(MAXTIME));
201 TEST_ASSERT_EQUAL_INT(-1, sut.Get(MAXTIME));
211 static void test_GetFlush(
void) {
212 TEST_ASSERT_EQUAL_INT(-1, sut.Get(MAXTIME));
216 TEST_ASSERT_EQUAL_INT(-1, sut.Get(MAXTIME));
219 static void test_GetFlushEmptyBuffer(
void) {
220 TEST_ASSERT_EQUAL_INT(-1, sut.Get(MAXTIME));
222 TEST_ASSERT_EQUAL_INT(-1, sut.Get(MAXTIME));
231 static void test_SetBaud(
void) {
232 TEST_ASSERT_TRUE(sut.SetBaud(9600));
235 static void test_SetBaudTooHigh(
void) {
236 TEST_ASSERT_EQUAL_INT(0, sut.SetBaud(1000000));
239 static void test_SetBaudToZero(
void) {
240 TEST_ASSERT_EQUAL_INT(0, sut.SetBaud(0));
243 static void test_SetBaudTransmitAfterBaudChange(
void) {
246 TEST_ASSERT_EQUAL_INT(
'a', sut.Get(MAXTIME));
249 static void test_Setbaudclock(
void) {
250 TEST_ASSERT_TRUE(sut.SetBaudClock(9600, 80000000));
256 static void test_GetBuffer(
void) {
257 char string[] =
"Hello World!";
259 char inputBuffer[size + 1];
260 inputBuffer[size] = 0;
261 sut.PutFormatted(
string);
262 TEST_ASSERT_EQUAL_INT(size, sut.Get(inputBuffer, size, MAXTIME));
263 TEST_ASSERT_EQUAL_STRING(
string, inputBuffer);
266 static void test_GetBufferString(
void) {
267 char string[] =
"Hello World!\n";
270 sut.PutFormatted(
string);
271 TEST_ASSERT_EQUAL_INT(size, sut.Get(buffer,
'\n'));
272 TEST_ASSERT_EQUAL_STRING(
string, buffer);
277 static void transmitAlphabet(
void * param) {
279 for (
int i =
'A'; i <=
'z'; i++) {
288 static void test_CTSPinBasic(
void) {
290 sut.Start(rxpin, txpin, baud, ctspin);
293 int *stack = (
int*) malloc(stacksize);
294 cogstart(transmitAlphabet, NULL, stack, stacksize);
305 while (current != -1) {
307 current = sut.Get(MAXTIME);
313 OUTA &= ~(1 << rtspin);
316 for (
int i = last + 1; i <=
'z'; i++) {
317 TEST_ASSERT_EQUAL_INT(i, sut.Get(MAXTIME));
320 TEST_ASSERT_EQUAL_INT(-1, sut.Get(0));
325 static void test_PutBuffer(
void) {
326 char data [] =
"Hello, long string!";
327 const int length = strlen(data) + 1;
329 char inputbuffer[length];
331 TEST_ASSERT_EQUAL_INT(length, sut.Put(data, length));
333 sut.Get(inputbuffer, length, MAXTIME);
335 TEST_ASSERT_EQUAL_STRING(data, inputbuffer);
339 static void test_PutBufferNullTerminatedString(
void) {
340 char data [] =
"Hello, long string!";
341 const int length = strlen(data);
343 char inputbuffer[length];
345 TEST_ASSERT_EQUAL_INT(length, sut.Put(data));
347 sut.Get(inputbuffer, length, MAXTIME);
349 TEST_ASSERT_EQUAL_MEMORY(data, inputbuffer, length);
355 static void test_GetCountEmpty(
void) {
356 TEST_ASSERT_EQUAL_INT(0, sut.GetCount());
359 static void test_GetCountOne(
void) {
362 TEST_ASSERT_EQUAL_INT(1, sut.GetCount());
365 static void test_GetCountFew(
void) {
373 static void test_GetCountWrapAround(
void) {
384 TEST_ASSERT_EQUAL_INT(3, sut.GetCount());