aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2020-11-24 14:03:19 -0700
committerJosh Rahm <joshuarahm@gmail.com>2020-11-24 14:03:19 -0700
commit351ff7059a5bacb322664412a8c62ee4640b33bf (patch)
tree53ef3fb16c5742c2edc45e633d80f6e16896f864 /tests
parent6a1e0acc14b62c00317ac61c6ad6d8ffe441be4f (diff)
downloadstm32l4-351ff7059a5bacb322664412a8c62ee4640b33bf.tar.gz
stm32l4-351ff7059a5bacb322664412a8c62ee4640b33bf.tar.bz2
stm32l4-351ff7059a5bacb322664412a8c62ee4640b33bf.zip
Update .clang-format and run it on filse
Diffstat (limited to 'tests')
-rw-r--r--tests/test_dma.c60
-rw-r--r--tests/test_gpio.c17
-rw-r--r--tests/test_irq.c7
-rw-r--r--tests/test_lib.c2
-rw-r--r--tests/test_memory.c61
-rw-r--r--tests/test_spi.c3
-rw-r--r--tests/test_usart.c6
7 files changed, 61 insertions, 95 deletions
diff --git a/tests/test_dma.c b/tests/test_dma.c
index 50cdb5b..f9b6a26 100644
--- a/tests/test_dma.c
+++ b/tests/test_dma.c
@@ -1,12 +1,12 @@
-#include "test_harness.h"
+#include <memory.h>
+#include <stdio.h>
+#include <stdlib.h>
+
#include "arch/stm32l4xxx/peripherals/dma.h"
#include "arch/stm32l4xxx/peripherals/rcc.h"
#include "arch/stm32l4xxx/peripherals/usart.h"
#include "kern/dma/dma_manager.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>
+#include "test_harness.h"
TEST(dma, smoke)
{
@@ -51,9 +51,7 @@ TEST(dma, regset_pl)
ASSERT_EQ(reg, (1 << 12));
- ASSERT_EQ(
- regget(reg, dma_cc_pl),
- DMA_PRIORITY_LEVEL_MEDIUM);
+ ASSERT_EQ(regget(reg, dma_cc_pl), DMA_PRIORITY_LEVEL_MEDIUM);
return 0;
}
@@ -63,20 +61,13 @@ TEST(dma_peri, select_peripheral)
int ec;
dma_mem2p_channel_t chan =
- select_dma_channel_mem2p(
- DMA1_PERIPH_USART2_TX,
- &opts,
- &ec);
+ select_dma_channel_mem2p(DMA1_PERIPH_USART2_TX, &opts, &ec);
ASSERT_EQ(DMA1.channel_config[6].cpa_r, ptr2reg(&USART2.td_r));
- ASSERT_EQ(
- regget(DMA1.channel_config[6].cc_r, dma_cc_dir),
- READ_FROM_MEMORY);
+ ASSERT_EQ(regget(DMA1.channel_config[6].cc_r, dma_cc_dir), READ_FROM_MEMORY);
- ASSERT_EQ(
- regget(DMA1.channel_config[6].cc_r, dma_cc_minc),
- 1);
+ ASSERT_EQ(regget(DMA1.channel_config[6].cc_r, dma_cc_minc), 1);
ASSERT_EQ(
regget(DMA1.channel_config[6].cc_r, dma_cc_pl),
@@ -99,26 +90,17 @@ TEST(dma_peri, unable_to_realloc)
int ec = 0;
dma_mem2p_channel_t chan =
- select_dma_channel_mem2p(
- DMA1_PERIPH_USART2_TX,
- &opts,
- &ec);
+ select_dma_channel_mem2p(DMA1_PERIPH_USART2_TX, &opts, &ec);
ASSERT_EQ(ec, 0);
- select_dma_channel_p2mem(
- DMA1_PERIPH_USART2_TX,
- &opts,
- &ec);
+ select_dma_channel_p2mem(DMA1_PERIPH_USART2_TX, &opts, &ec);
ASSERT_EQ(ec, DMA_ERROR_CHANNEL_IN_USE);
-
+
release_dma_channel(chan.c_);
- chan = select_dma_channel_mem2p(
- DMA1_PERIPH_USART2_TX,
- &opts,
- &ec);
+ chan = select_dma_channel_mem2p(DMA1_PERIPH_USART2_TX, &opts, &ec);
ASSERT_EQ(ec, 0);
@@ -130,16 +112,14 @@ TEST(dma_peri, select_mem2mem)
{
int ec = 0;
dma_opts_t opts = DEFAULT_DMA_OPTS;
- dma_mem2mem_channel_t chan =
- select_dma_channel_mem2mem(-1, &opts, &ec);
+ dma_mem2mem_channel_t chan = select_dma_channel_mem2mem(-1, &opts, &ec);
ASSERT_EQ(ec, 0);
ASSERT_EQ(chan.c_.dma, 1);
ASSERT_EQ(chan.c_.chan, 6);
- dma_mem2mem_channel_t chan2 =
- select_dma_channel_mem2mem(-1, &opts, &ec);
+ dma_mem2mem_channel_t chan2 = select_dma_channel_mem2mem(-1, &opts, &ec);
ASSERT_EQ(ec, 0);
@@ -148,8 +128,7 @@ TEST(dma_peri, select_mem2mem)
release_dma_channel(chan.c_);
- dma_mem2mem_channel_t chan3 =
- select_dma_channel_mem2mem(-1, &opts, &ec);
+ dma_mem2mem_channel_t chan3 = select_dma_channel_mem2mem(-1, &opts, &ec);
ASSERT_EQ(chan3.c_.dma, 1);
ASSERT_EQ(chan3.c_.chan, 6);
@@ -165,9 +144,8 @@ TEST(dma_peri, select_mem2mem_2)
dma_mem2mem_channel_t chans[14];
int ec;
- for (int i = 0; i < 14; ++ i) {
- chans[i] = select_dma_channel_mem2mem(
- -1, &opts, &ec);
+ for (int i = 0; i < 14; ++i) {
+ chans[i] = select_dma_channel_mem2mem(-1, &opts, &ec);
ASSERT_EQ(ec, 0);
}
@@ -175,7 +153,7 @@ TEST(dma_peri, select_mem2mem_2)
select_dma_channel_mem2mem(-1, &opts, &ec);
ASSERT_EQ(ec, DMA_ERROR_CHANNEL_IN_USE);
- for (int i = 0; i < 14; ++ i) {
+ for (int i = 0; i < 14; ++i) {
if (i < 7) {
ASSERT_EQ(chans[i].c_.chan, 6 - i);
ASSERT_EQ(chans[i].c_.dma, 1);
diff --git a/tests/test_gpio.c b/tests/test_gpio.c
index bcb953c..dd9c957 100644
--- a/tests/test_gpio.c
+++ b/tests/test_gpio.c
@@ -1,7 +1,6 @@
-#include "test_harness.h"
-
#include "arch/stm32l4xxx/peripherals/rcc.h"
#include "kern/gpio/gpio_manager.h"
+#include "test_harness.h"
TEST(gpio_manager, smell)
{
@@ -46,7 +45,7 @@ TEST(gpio_manager, alternate)
ASSERT_EQ(ec, 0);
- gpio_port_config_t* gpioa = (gpio_port_config_t*) GPIOA_BASE;
+ gpio_port_config_t* gpioa = (gpio_port_config_t*)GPIOA_BASE;
ASSERT_EQ(regget(gpioa->mode_r, gpio_mode_n(15)), GPIO_MODE_ALTERNATE);
ASSERT_EQ(regget(gpioa->mode_r, gpio_mode_n(2)), GPIO_MODE_ALTERNATE);
@@ -75,8 +74,7 @@ TEST(gpio_manager, bad_pin)
int ec;
/* Pretending to start the USART. */
- gpio_enable_alternate_function(
- GPIO_ALTERNATE_FUNCTION_USART2_RX, 99, &ec);
+ gpio_enable_alternate_function(GPIO_ALTERNATE_FUNCTION_USART2_RX, 99, &ec);
ASSERT_EQ(ec, GPIO_ERROR_INVALID_PIN);
@@ -103,7 +101,6 @@ TEST(gpio_manager, alternate_then_reserve_fail)
TEST(gpio_manager, get_gpio_pin_port_off)
{
-
gpio_port_config_t* cfg;
int off;
get_gpio_pin_port_off(GPIO_PIN_PA5, &cfg, &off);
@@ -127,12 +124,14 @@ TEST(gpio_manager, sets_gpio_settings)
reserve_gpio_pin(GPIO_PIN_PA2, &opts, &ec);
ASSERT_EQ(ec, 0);
- gpio_port_config_t* gpioa = (gpio_port_config_t*) GPIOA_BASE;
+ gpio_port_config_t* gpioa = (gpio_port_config_t*)GPIOA_BASE;
ASSERT_EQ(regget(gpioa->mode_r, gpio_mode_n(2)), GPIO_MODE_OUTPUT);
ASSERT_EQ(regget(gpioa->pupd_r, gpio_pupd_n(2)), GPIO_PULL_DIR_NONE);
- ASSERT_EQ(regget(gpioa->ospeed_r, gpio_ospeed_n(2)), GPIO_OUTPUT_SPEED_VERY_HIGH);
- ASSERT_EQ(regget(gpioa->otype_r, gpio_otype_n(2)), GPIO_OUTPUT_TYPE_PUSH_PULL);
+ ASSERT_EQ(
+ regget(gpioa->ospeed_r, gpio_ospeed_n(2)), GPIO_OUTPUT_SPEED_VERY_HIGH);
+ ASSERT_EQ(
+ regget(gpioa->otype_r, gpio_otype_n(2)), GPIO_OUTPUT_TYPE_PUSH_PULL);
return 0;
}
diff --git a/tests/test_irq.c b/tests/test_irq.c
index 3c4ee9c..6fe20e4 100644
--- a/tests/test_irq.c
+++ b/tests/test_irq.c
@@ -1,11 +1,10 @@
-#include "test_harness.h"
-
#include "arch/stm32l4xxx/peripherals/irq.h"
#include "arch/stm32l4xxx/peripherals/nvic.h"
+#include "test_harness.h"
TEST(irq, nvic)
{
- interrupt_set_t is = { 0 };
+ interrupt_set_t is = {0};
interrupt_set_add(&is, IRQ_USART2);
interrupt_set_add(&is, IRQ_USART3);
@@ -20,7 +19,7 @@ TEST(irq, nvic)
TEST(irq, nvic_edgecase)
{
- interrupt_set_t is = { 0 };
+ interrupt_set_t is = {0};
interrupt_set_add(&is, IRQ_WWDG_IRQ);
interrupt_set_add(&is, IRQ_I2C1_ER);
diff --git a/tests/test_lib.c b/tests/test_lib.c
index 33076c2..e9361c4 100644
--- a/tests/test_lib.c
+++ b/tests/test_lib.c
@@ -1,5 +1,5 @@
-#include "test_harness.h"
#include "kern/lib.h"
+#include "test_harness.h"
TEST(lib, hexify)
{
diff --git a/tests/test_memory.c b/tests/test_memory.c
index 6e523aa..0f4ccab 100644
--- a/tests/test_memory.c
+++ b/tests/test_memory.c
@@ -5,9 +5,9 @@
#include <stdlib.h>
#include "arch.h"
-#include "test_harness.c"
#include "kern/common.h"
#include "kern/mem.h"
+#include "test_harness.c"
struct TEST_STRUCT {
uint32_t array[3];
@@ -23,12 +23,12 @@ typedef struct KALLOC_NODE {
uint32_t header;
struct {
/* Is this memory block currently in use (hasn't been kfree'd) */
- bool used:1;
+ bool used : 1;
/* Number of words allocated. Does not include the header. */
- uint16_t size:12;
+ uint16_t size : 12;
/* The location of the previous block (in WORDS from offest) */
- uint16_t prev:12;
- uint8_t canary:7;
+ uint16_t prev : 12;
+ uint8_t canary : 7;
} PACKED;
};
@@ -43,11 +43,10 @@ static void wipeout_kalloc()
kalloc_start = NULL;
}
-
static struct TEST_STRUCT* new_test_struct()
{
struct TEST_STRUCT* ret = kalloc(sizeof(struct TEST_STRUCT));
-
+
ret->array[0] = 1;
ret->array[1] = 2;
ret->array[2] = 3;
@@ -58,20 +57,18 @@ static struct TEST_STRUCT* new_test_struct()
static struct TEST_STRUCT2* new_test_struct2()
{
struct TEST_STRUCT2* ret = kalloc(sizeof(struct TEST_STRUCT2));
-
- for (int i = 0; i < 10; ++ i) {
+
+ for (int i = 0; i < 10; ++i) {
ret->array[i] = i;
}
return ret;
}
-#define ASSERT_CHAIN(t1, t2) \
- ASSERT_EQ(V(t1) + sizeof(*t1) + 4, V(t2))
+#define ASSERT_CHAIN(t1, t2) ASSERT_EQ(V(t1) + sizeof(*t1) + 4, V(t2))
TEST(memory, kalloc)
{
-
#define V(x) ((void*)(x))
struct TEST_STRUCT* test1 = new_test_struct();
struct TEST_STRUCT2* test2 = new_test_struct2();
@@ -90,14 +87,9 @@ TEST(memory, kalloc)
ASSERT_CHAIN(test3, test4);
ASSERT_CHAIN(test4, test5);
-
char buf[1024];
if (debug_kalloc_assert_consistency(buf, 1024)) {
- fprintf(
- stderr,
- "Consistency check failed. (%s:%d)\n",
- __FILE__,
- __LINE__);
+ fprintf(stderr, "Consistency check failed. (%s:%d)\n", __FILE__, __LINE__);
fprintf(stderr, buf);
ASSERT_TRUE(false);
}
@@ -114,7 +106,7 @@ struct UNEVEN_STRUCT {
struct UNEVEN_STRUCT* new_uneven_struct()
{
struct UNEVEN_STRUCT* ret = kalloc(sizeof(struct UNEVEN_STRUCT));
-
+
ret->arr[0] = 1;
ret->arr[1] = 2;
ret->arr[2] = 3;
@@ -124,8 +116,7 @@ struct UNEVEN_STRUCT* new_uneven_struct()
return ret;
}
-#define size_for(n) \
- (((n) / 4) + ((n) % 4 != 0))
+#define size_for(n) (((n) / 4) + ((n) % 4 != 0))
TEST(memory, uneven_kalloc)
{
@@ -161,7 +152,7 @@ TEST(memory, kalloc_free)
kfree(test1);
kfree(test5);
- ASSERT_EQ((int) kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
+ ASSERT_EQ((int)kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
test1 = new_test_struct();
test2 = new_test_struct2();
@@ -175,7 +166,7 @@ TEST(memory, kalloc_free)
kfree(test4);
kfree(test5);
- ASSERT_EQ((int) kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
+ ASSERT_EQ((int)kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
test1 = new_test_struct();
test2 = new_test_struct2();
@@ -189,7 +180,7 @@ TEST(memory, kalloc_free)
kfree(test2);
kfree(test5);
- ASSERT_EQ((int) kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
+ ASSERT_EQ((int)kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
wipeout_kalloc();
@@ -262,10 +253,10 @@ TEST(memory, consistency_stress)
}
int i;
- void* allocd[NRUNS] = { 0 };
+ void* allocd[NRUNS] = {0};
char buf[1024];
- for (i = 0; i < NRUNS; ++ i) {
+ for (i = 0; i < NRUNS; ++i) {
size_t nalloc = rand() % 20;
allocd[i] = kalloc(nalloc);
@@ -326,23 +317,23 @@ TEST(memory, consistency_stress)
}
}
- for(i = 0; i < NRUNS; ++ i) {
+ for (i = 0; i < NRUNS; ++i) {
if (allocd[i]) {
kfree(allocd[i]);
}
if (debug_kalloc_assert_consistency(buf, 1024)) {
- fprintf(
- stderr,
- "Consistency check failed. (At index=%d, %s:%d)\n",
- i,
- __FILE__,
- __LINE__);
+ fprintf(
+ stderr,
+ "Consistency check failed. (At index=%d, %s:%d)\n",
+ i,
+ __FILE__,
+ __LINE__);
fprintf(stderr, buf);
ASSERT_TRUE(false);
}
}
- ASSERT_EQ((int) kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
+ ASSERT_EQ((int)kalloc_start->size * 4, MAX_HEAP_SIZE - 4);
return 0;
}
@@ -364,7 +355,7 @@ TEST(memory, kalloc_free_alloc)
struct TEST_STRUCT2* test6 = new_test_struct2();
// test_6 should have been allocated in test_4's spot.
- ASSERT_EQ(test6, test4);
+ ASSERT_EQ(test6, test4);
kfree(test2);
struct TEST_STRUCT* test7 = new_test_struct();
diff --git a/tests/test_spi.c b/tests/test_spi.c
index cc25d6e..866f6e8 100644
--- a/tests/test_spi.c
+++ b/tests/test_spi.c
@@ -1,6 +1,5 @@
-#include "test_harness.h"
-
#include "arch/stm32l4xxx/peripherals/spi.h"
+#include "test_harness.h"
TEST(spi, smoke)
{
diff --git a/tests/test_usart.c b/tests/test_usart.c
index b19d687..82b6ce7 100644
--- a/tests/test_usart.c
+++ b/tests/test_usart.c
@@ -1,8 +1,8 @@
-#include "test_harness.h"
-#include "arch/stm32l4xxx/peripherals/usart.h"
-
#include <stdlib.h>
+#include "arch/stm32l4xxx/peripherals/usart.h"
+#include "test_harness.h"
+
TEST(usart, enable_dma)
{
__IO usart_t* usart = &USART1;