summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorScott Shawcroft <[email protected]>2019-01-08 14:10:40 -0800
committerScott Shawcroft <[email protected]>2019-01-08 14:10:40 -0800
commit52abbec7c5568f1ef4d6d5a0420fdd414efd192d (patch)
tree5675befdfa5bd513e2403b7255932a391f25f61e /tests
parent7016d7fa54b40268ac6315602bc9bf465c1b99e4 (diff)
Remove txbuf in favor of fifo.
Fifo incurs a second copy into a USB buffer but this ensures the correct USB buffer alignment. Some LPC chips require 64 byte alignment that txbuf couldn't do.
Diffstat (limited to 'tests')
-rw-r--r--tests/common/Makefile91
-rw-r--r--tests/common/build/results/test_txbuf.txt8
-rw-r--r--tests/common/test/test_txbuf.c145
3 files changed, 0 insertions, 244 deletions
diff --git a/tests/common/Makefile b/tests/common/Makefile
deleted file mode 100644
index 2810fbae0..000000000
--- a/tests/common/Makefile
+++ /dev/null
@@ -1,91 +0,0 @@
-ifeq ($(OS),Windows_NT)
- ifeq ($(shell uname -s),) # not in a bash-like shell
- CLEANUP = del /F /Q
- MKDIR = mkdir
- else # in a bash-like shell, like msys
- CLEANUP = rm -f
- MKDIR = mkdir -p
- endif
- TARGET_EXTENSION=.exe
-else
- CLEANUP = rm -f
- MKDIR = mkdir -p
- TARGET_EXTENSION=out
-endif
-
-.PHONY: clean
-.PHONY: test
-
-PATHU = ../vendor/unity/src/
-PATHS = ../../src/
-PATHT = test/
-PATHB = build/
-PATHD = build/depends/
-PATHO = build/objs/
-PATHR = build/results/
-
-BUILD_PATHS = $(PATHB) $(PATHD) $(PATHO) $(PATHR)
-
-SRCT = $(wildcard $(PATHT)*.c)
-
-$(info $(SRCT))
-
-COMPILE=gcc -c
-LINK=gcc
-DEPEND=gcc -MM -MG -MF
-CFLAGS=-I. -I$(PATHU) -I$(PATHS) -DTEST
-
-RESULTS = $(patsubst $(PATHT)test%.c,$(PATHR)test%.txt,$(SRCT) )
-
-PASSED = `grep -s PASS $(PATHR)*.txt`
-FAIL = `grep -s FAIL $(PATHR)*.txt`
-IGNORE = `grep -s IGNORE $(PATHR)*.txt`
-
-test: $(BUILD_PATHS) $(RESULTS)
- @echo "-----------------------\nIGNORES:\n-----------------------"
- @echo "$(IGNORE)"
- @echo "-----------------------\nFAILURES:\n-----------------------"
- @echo "$(FAIL)"
- @echo "-----------------------\nPASSED:\n-----------------------"
- @echo "$(PASSED)"
- @echo "\nDONE"
-
-$(PATHR)%.txt: $(PATHB)%.$(TARGET_EXTENSION)
- -./$< > $@ 2>&1
-
-$(PATHB)test_%.$(TARGET_EXTENSION): $(PATHO)test_%.o $(PATHO)tusb_%.o $(PATHU)unity.o #$(PATHD)test%.d
- $(LINK) -o $@ $^
-
-$(PATHO)%.o:: $(PATHT)%.c
- $(COMPILE) $(CFLAGS) $< -o $@
-
-$(PATHO)%.o:: $(PATHS)common/%.c
- $(COMPILE) $(CFLAGS) $< -o $@
-
-$(PATHO)%.o:: $(PATHU)%.c $(PATHU)%.h
- $(COMPILE) $(CFLAGS) $< -o $@
-
-$(PATHD)%.d:: $(PATHT)%.c
- $(DEPEND) $@ $<
-
-$(PATHB):
- $(MKDIR) $(PATHB)
-
-$(PATHD):
- $(MKDIR) $(PATHD)
-
-$(PATHO):
- $(MKDIR) $(PATHO)
-
-$(PATHR):
- $(MKDIR) $(PATHR)
-
-clean:
- $(CLEANUP) $(PATHO)*.o
- $(CLEANUP) $(PATHB)*.$(TARGET_EXTENSION)
- $(CLEANUP) $(PATHR)*.txt
-
-.PRECIOUS: $(PATHB)test%.$(TARGET_EXTENSION)
-.PRECIOUS: $(PATHD)%.d
-.PRECIOUS: $(PATHO)%.o
-.PRECIOUS: $(PATHR)%.txt
diff --git a/tests/common/build/results/test_txbuf.txt b/tests/common/build/results/test_txbuf.txt
deleted file mode 100644
index a763a4717..000000000
--- a/tests/common/build/results/test_txbuf.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-test/test_txbuf.c:140:test_normal:PASS
-test/test_txbuf.c:141:test_nearly_full:PASS
-test/test_txbuf.c:142:test_wrap_around:PASS
-test/test_txbuf.c:143:test_wrap_around_too_much:PASS
-
------------------------
-4 Tests 0 Failures 0 Ignored
-OK
diff --git a/tests/common/test/test_txbuf.c b/tests/common/test/test_txbuf.c
deleted file mode 100644
index efa442f04..000000000
--- a/tests/common/test/test_txbuf.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/**************************************************************************/
-/*!
- @file test_fifo.c
- @author Scott Shawcroft
-
- @section LICENSE
-
- Software License Agreement (BSD License)
-
- Copyright (c) 2019, Scott Shawcroft
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- This file is part of the tinyusb stack.
-*/
-/**************************************************************************/
-
-#include "unity.h"
-#include "common/tusb_txbuf.h"
-
-uint32_t xfer_count = 0;
-uint32_t freshly_transmitted = 0;
-
-bool mock_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes) {
- TEST_ASSERT_EQUAL_INT_MESSAGE(0, ((size_t) buffer) % 4, "Transferred buffer not word aligned.");
- xfer_count++;
- freshly_transmitted += total_bytes;
- return true;
-}
-
-tu_txbuf_t txbuf;
-__attribute__((aligned(4))) uint8_t buffer[16];
-
-uint8_t data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
-
-void setUp(void) {
- tu_txbuf_config(&txbuf, buffer, 16, mock_xfer);
- tu_txbuf_set_ep_addr(&txbuf, 1);
-}
-
-void tearDown(void) {
- xfer_count = 0;
- freshly_transmitted = 0;
-}
-
-void xfer_callback(void) {
- uint32_t previously_transmitted = freshly_transmitted;
- freshly_transmitted = 0;
-
- tu_txbuf_transmit_done_cb(&txbuf, previously_transmitted);
-}
-
-// Test that we transfer immediately at the start and that the pointer is rounded to a word.
-void test_normal(void) {
- uint16_t written = tu_txbuf_write_n(&txbuf, data, 4);
- TEST_ASSERT_EQUAL_INT(4, written);
- TEST_ASSERT_EQUAL_INT(1, xfer_count);
- xfer_callback();
- TEST_ASSERT_EQUAL_INT(1, xfer_count);
-}
-
-// Test that we only accept the data we have room for.
-void test_nearly_full(void) {
- uint16_t written = tu_txbuf_write_n(&txbuf, data, 11);
- TEST_ASSERT_EQUAL_INT(11, written);
- TEST_ASSERT_EQUAL_INT(1, xfer_count);
-
- written = tu_txbuf_write_n(&txbuf, data, 11);
- // We only have space for 4 more bytes because 11 + padding are being written.
- TEST_ASSERT_EQUAL_INT(4, written);
-
- // Callback triggers a second write of remaining data.
- xfer_callback();
- TEST_ASSERT_EQUAL_INT(2, xfer_count);
- TEST_ASSERT_EQUAL_INT(4, freshly_transmitted);
-}
-
-// Test that we only accept the data even when we have to wrap around.
-void test_wrap_around(void) {
- uint16_t written = tu_txbuf_write_n(&txbuf, data, 11);
- TEST_ASSERT_EQUAL_INT(11, written);
- TEST_ASSERT_EQUAL_INT(1, xfer_count);
- xfer_callback();
- TEST_ASSERT_EQUAL_INT(1, xfer_count);
-
- written = tu_txbuf_write_n(&txbuf, data, 11);
- // We can queue all 11 bytes but they are split.
- TEST_ASSERT_EQUAL_INT(11, written);
- // Four immediately and seven more after the callback.
- TEST_ASSERT_EQUAL_INT(2, xfer_count);
- TEST_ASSERT_EQUAL_INT(4, freshly_transmitted);
- xfer_callback();
- TEST_ASSERT_EQUAL_INT(7, freshly_transmitted);
- TEST_ASSERT_EQUAL_INT(3, xfer_count);
-}
-
-// Test that we only accept the data even when we have to wrap around.
-void test_wrap_around_too_much(void) {
- uint16_t written = tu_txbuf_write_n(&txbuf, data, 11);
- TEST_ASSERT_EQUAL_INT(11, written);
- TEST_ASSERT_EQUAL_INT(1, xfer_count);
- xfer_callback();
- TEST_ASSERT_EQUAL_INT(1, xfer_count);
-
- written = tu_txbuf_write_n(&txbuf, data, 17);
- // We can queue 16 of 17 bytes but they are split.
- TEST_ASSERT_EQUAL_INT(16, written);
- // Four immediately and 12 more after the callback.
- TEST_ASSERT_EQUAL_INT(2, xfer_count);
- TEST_ASSERT_EQUAL_INT(4, freshly_transmitted);
- xfer_callback();
- TEST_ASSERT_EQUAL_INT(12, freshly_transmitted);
- TEST_ASSERT_EQUAL_INT(3, xfer_count);
-}
-
-int main(void)
-{
-UNITY_BEGIN();
-RUN_TEST(test_normal);
-RUN_TEST(test_nearly_full);
-RUN_TEST(test_wrap_around);
-RUN_TEST(test_wrap_around_too_much);
-return UNITY_END();
-}