Skip to content
Permalink
Browse files

style: samples/tests: add braces around if/while statements

Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
  • Loading branch information...
nashif authored and carlescufi committed Jun 4, 2019
1 parent 4c32258 commit 2fb19fcbdd46b543f3f32f1fd2e5135a7fd785ce
@@ -126,8 +126,9 @@ void rx_str_thread(void *msgq, void *can_dev_param, void *unused)

while (1) {
k_msgq_get((struct k_msgq *)msgq, &msg, K_FOREVER);
for (int i = 0; i < msg.dlc; i++)
for (int i = 0; i < msg.dlc; i++) {
printk("%c", msg.data[i]);
}
}
}

@@ -575,19 +575,21 @@ void main(void)

while (1) {
uart_line_ctrl_get(dev, LINE_CTRL_DTR, &dtr);
if (dtr)
if (dtr) {
break;
}
}

uart_dev = dev;

LOG_DBG("DTR set, continue");

ret = uart_line_ctrl_get(dev, LINE_CTRL_BAUD_RATE, &baudrate);
if (ret)
if (ret) {
printk("Failed to get baudrate, ret code %d\n", ret);
else
} else {
printk("Baudrate detected: %d\n", baudrate);
}

LOG_INF("USB serial initialized");

@@ -96,11 +96,13 @@ void qsort(void *a, size_t n, size_t es, cmp_t *cmp)
loop:
swap_cnt = 0;
if (n < 7) {
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) {
for (pl = pm;
pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
pl -= es)
pl -= es) {
swapfunc(pl, pl - es, es);
}
}
return;
}
pm = (char *)a + (n / 2) * es;
@@ -137,19 +139,23 @@ void qsort(void *a, size_t n, size_t es, cmp_t *cmp)
}
pc -= es;
}
if (pb > pc)
if (pb > pc) {
break;
}

swapfunc(pb, pc, es);
swap_cnt = 1;
pb += es;
pc -= es;
}
if (swap_cnt == 0) { /* Switch to insertion sort */
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) {
for (pl = pm;
pl > (char *)a && CMP(thunk, pl - es, pl) > 0;
pl -= es)
pl -= es) {
swapfunc(pl, pl - es, es);
}
}
return;
}

@@ -240,8 +240,9 @@ int vendor_handle_req(struct usb_setup_packet *pSetup,
/* Get URL request */
u8_t index = GET_DESC_INDEX(pSetup->wValue);

if (index == 0U || index > NUMBER_OF_ALLOWED_ORIGINS)
if (index == 0U || index > NUMBER_OF_ALLOWED_ORIGINS) {
return -ENOTSUP;
}

*data = (u8_t *)(&webusb_origin_url);
*len = sizeof(webusb_origin_url);
@@ -90,8 +90,9 @@ int webusb_custom_handle_req(struct usb_setup_packet *pSetup,

/* Call the callback */
if ((req_handlers && req_handlers->custom_handler) &&
(!req_handlers->custom_handler(pSetup, len, data)))
(!req_handlers->custom_handler(pSetup, len, data))) {
return 0;
}

return -ENOTSUP;
}
@@ -110,8 +111,9 @@ int webusb_vendor_handle_req(struct usb_setup_packet *pSetup,
{
/* Call the callback */
if ((req_handlers && req_handlers->vendor_handler) &&
(!req_handlers->vendor_handler(pSetup, len, data)))
(!req_handlers->vendor_handler(pSetup, len, data))) {
return 0;
}

return -ENOTSUP;
}
@@ -56,8 +56,10 @@ char enig_enc(char pt)
printk("EE : %02x\n", tmpIndex);
#endif
/* if error return */
if (tmpIndex == -1)
if (tmpIndex == -1) {
return (char)0xFF;
}

tmpIndex = (W1[IMOD(IW1, tmpIndex)] + WHEEL_SIZE - IW1) % WHEEL_SIZE;
#ifdef DBUG
printk("EE i1: %02x\n", tmpIndex);
@@ -96,9 +96,10 @@ static void do_test_gen_gz_inc_file(const unsigned char gz_inc_file[],
/* Modification time field (4 bytes) in
* the gzip header.
*/
if (mtime != NULL) /* NULL arg = random "now" */
if (mtime != NULL) { /* NULL arg = random "now" */
zassert_equal(gz_inc_file[i], mtime[i-4],
"Invalid mtime in inc file");
}

continue;
}
@@ -152,8 +152,10 @@ void mutex_bench(void)
/* If timer interrupt occurs we need to omit that sample*/
s64_t after = k_uptime_get();

if (after - before)
if (after - before) {
continue;
}

count++;

mutex_lock_diff += (mutex_lock_end_time -
@@ -198,23 +198,27 @@ static int test_task(u32_t chan_id, u32_t blen, u32_t block_count)
/* Intentionally break has been omitted (fall-through) */
switch (block_count) {
case 4:
if (strcmp(tx_data4, rx_data4) != 0)
if (strcmp(tx_data4, rx_data4) != 0) {
return -1;
}
printk("%s\n", rx_data4);

case 3:
if (strcmp(tx_data3, rx_data3) != 0)
if (strcmp(tx_data3, rx_data3) != 0) {
return -1;
}
printk("%s\n", rx_data3);

case 2:
if (strcmp(tx_data2, rx_data2) != 0)
if (strcmp(tx_data2, rx_data2) != 0) {
return -1;
}
printk("%s\n", rx_data2);

case 1:
if (strcmp(tx_data, rx_data) != 0)
if (strcmp(tx_data, rx_data) != 0) {
return -1;
}
printk("%s\n", rx_data);
break;

@@ -102,8 +102,9 @@ static int test_fifo_read(void)
TC_PRINT("Please send characters to serial console\n");

data_received = false;
while (data_received == false)
;
while (data_received == false) {
}

/* Verify uart_irq_rx_disable() */
uart_irq_rx_disable(uart_dev);

@@ -22,8 +22,8 @@ static int test_poll_in(void)

/* Verify uart_poll_in() */
while (1) {
while (uart_poll_in(uart_dev, &recv_char) < 0)
;
while (uart_poll_in(uart_dev, &recv_char) < 0) {
}

TC_PRINT("%c", recv_char);

@@ -40,21 +40,19 @@ void test_clock_uptime(void)

/**TESTPOINT: uptime elapse*/
t64 = k_uptime_get();
while (k_uptime_get() < (t64 + 5))
while (k_uptime_get() < (t64 + 5)) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

/**TESTPOINT: uptime elapse lower 32-bit*/
t32 = k_uptime_get_32();
while (k_uptime_get_32() < (t32 + 5))
while (k_uptime_get_32() < (t32 + 5)) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

/**TESTPOINT: uptime straddled ms boundary*/
t32 = k_uptime_get_32();
@@ -64,22 +62,20 @@ void test_clock_uptime(void)
/**TESTPOINT: uptime delta*/
d64 = k_uptime_delta(&d64);
/* Note: this will stall if the systick period < 5ms */
while (k_uptime_delta(&d64) < 5)
while (k_uptime_delta(&d64) < 5) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

/**TESTPOINT: uptime delta lower 32-bit*/
k_uptime_delta_32(&d64);
/* Note: this will stall if the systick period < 5ms */
while (k_uptime_delta_32(&d64) < 5)
while (k_uptime_delta_32(&d64) < 5) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

/**TESTPOINT: uptime delta straddled ms boundary*/
k_uptime_delta_32(&d64);
@@ -101,23 +97,21 @@ void test_clock_cycle(void)
c32 = k_cycle_get_32();
/*break if cycle counter wrap around*/
while (k_cycle_get_32() > c32 &&
k_cycle_get_32() < (c32 + sys_clock_hw_cycles_per_tick()))
k_cycle_get_32() < (c32 + sys_clock_hw_cycles_per_tick())) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

/**TESTPOINT: cycle/uptime cross check*/
c0 = k_cycle_get_32();
ALIGN_MS_BOUNDARY;
t32 = k_uptime_get_32();
while (t32 == k_uptime_get_32())
while (t32 == k_uptime_get_32()) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

c1 = k_uptime_get_32();
/*avoid cycle counter wrap around*/
@@ -65,12 +65,11 @@ void test_timeout_order(void)
u32_t uptime = k_uptime_get_32();

/* sync on tick */
while (uptime == k_uptime_get_32())
while (uptime == k_uptime_get_32()) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

for (ii = 0; ii < NUM_TIMEOUTS; ii++) {
k_timer_start(&timer[ii], 100, 0);
@@ -124,8 +124,6 @@ void test_slice_reset(void)
while (k_uptime_get_32() == t32) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

@@ -137,8 +135,6 @@ void test_slice_reset(void)
while (k_cycle_get_32() - t32 < HALF_SLICE_SIZE_CYCLES) {
#if defined(CONFIG_ARCH_POSIX)
k_busy_wait(50);
#else
;
#endif
}

@@ -68,8 +68,9 @@ static void reset_results(void)
{
int i;

for (i = 0; i < NUM_TEST_ITEMS; i++)
for (i = 0; i < NUM_TEST_ITEMS; i++) {
results[i] = 0;
}

num_results = 0;
}

0 comments on commit 2fb19fc

Please sign in to comment.
You can’t perform that action at this time.