Skip to content

Commit

Permalink
Refactor nim2 (#24)
Browse files Browse the repository at this point in the history
* dev container
* test fixups
* print test headers
* use docker build
* fix nvs_entry_find
* fix esp_netif
* distinct type for XQueue pointer (helps compile errors)
* fix merge
  • Loading branch information
elcritch authored Jul 23, 2024
1 parent 46eb6ef commit ec9460b
Show file tree
Hide file tree
Showing 28 changed files with 40 additions and 29 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 20 additions & 10 deletions nesper.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.7.0"
version = "0.7.1"
author = "Jaremy Creechley"
description = "Nim wrappers for ESP-IDF (ESP32)"
license = "Apache-2.0"
Expand All @@ -20,39 +20,49 @@ requires "bytesequtils"
# Tasks
import os, strutils

proc header(msg: string) =
echo "\n\n", msg, "\n"
proc testExec(cmd: string) =
echo "running: ", cmd
exec(cmd)

proc general_tests() =
# Regular tests
header "=== Regular Tests ==="
for dtest in listFiles("tests/"):
if dtest.splitFile()[1].startsWith("t") and dtest.endsWith(".nim"):
echo("Testing: " & $dtest)
exec "nim c --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest]
testExec "nim c --verbosity:0 --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest]

proc driver_tests() =
# Driver tests
header "=== Driver Tests ==="
for dtest in listFiles("tests/driver/"):
if dtest.splitFile()[1].startsWith("t") and dtest.endsWith(".nim"):
echo("Testing: " & $dtest)
exec "nim c --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest]
echo("\nTesting: " & $dtest)
testExec "nim c --verbosity:0 --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest]

proc storage_tests() =
# Driver tests
# Storage tests
header "=== Storage Tests ==="
for dtest in listFiles("tests/storage/"):
if dtest.splitFile()[1].startsWith("t") and dtest.endsWith(".nim"):
echo("Testing: " & $dtest)
exec "nim c --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest]
echo("\nTesting: " & $dtest)
testExec "nim c --verbosity:0 --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest]

proc exec_tests() =
# Exec tests
header "=== Exec Tests ==="
for dtest in listFiles("tests/exec_tests/"):
if dtest.splitFile()[1].startsWith("t") and dtest.endsWith(".nim"):
echo("Testing: " & $dtest)
exec "nim c -r --cincludes:$2/tests/c_headers/mock/ $1" % [dtest, getCurrentDir()]
echo("\nTesting: " & $dtest)
testExec "nim c --verbosity:0 -r --cincludes:$2/tests/c_headers/mock/ $1" % [dtest, getCurrentDir()]

task test, "Runs the test suite":
general_tests()
driver_tests()
storage_tests()
# exec_tests()
exec_tests()

task test_general, "Runs the test suite":
general_tests()
Expand Down
1 change: 1 addition & 0 deletions src/nesper/build_utils/tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type
args: seq[string]
child_args: seq[string]
cachedir: string
esp_idf_major: string
esp_idf_version: string
wifi_args: string
debug: bool
Expand Down
7 changes: 4 additions & 3 deletions src/nesper/consts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ type

type
## *< a number that identifies an event with respect to a base
esp_event_handler_t* = proc (event_handler_arg: esp_event_base_t;
event_base: esp_event_base_t; event_id: int32;
event_data: pointer) {.cdecl.}
esp_event_handler_t* = proc (event_handler_arg: pointer;
event_base: esp_event_base_t;
event_id: int32;
event_data: pointer) {.cdecl.}

type
bits* = distinct int
Expand Down
1 change: 1 addition & 0 deletions src/nesper/esp/net/esp_netif.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ else:
export esp_netif_impl
export esp_netif_defaults

export esp_netif_impl
export esp_wifi_types
export esp_netif_ip_addr
export esp_netif_types
Expand Down
4 changes: 2 additions & 2 deletions src/nesper/ethernet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ when defined(ESP_IDF_V4_0):
import nesper/esp/net/tcpip_adapter
export tcpip_adapter
else:
import nesper/esp/net/esp_netif_types
import nesper/esp/net/esp_netif
import esp/net/esp_netif_types
import esp/net/esp_netif
export esp_netif_types
export esp_netif

Expand Down
2 changes: 1 addition & 1 deletion src/nesper/queues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import esp/queue
export queue

type
XQueue*[N] = pointer
XQueue*[N] = distinct pointer

template xQueueCreate*(uxQueueLength, uxItemSize: int): untyped =
xQueueCreate(UBaseType_t(uxQueueLength), UBaseType_t(uxItemSize))
Expand Down
9 changes: 3 additions & 6 deletions src/nesper/servers/rpc/router.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,12 @@ proc wrapError*(code: int, msg: string, id: JsonNode,
result = %* { "code": code, "id": id, "message": escapeJson(msg), "data": data }
if err != nil:
result["stacktrace"] = %* err.getStackTraceEntries()
echo "Error generated: ", "result: ", result, " id: ", id

template wrapException(body: untyped) =
template wrapException*(body: untyped) =
try:
body
except:
let msg = getCurrentExceptionMsg()
echo("control server: invalid input: error: ", msg)
let resp = rpcInvalidRequest(msg)
except Exception as err:
let resp = rpcInvalidRequest(err.msg)
return resp


Expand Down
10 changes: 5 additions & 5 deletions src/nesper/uarts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export uart
export consts
export gpios.gpio_num_t

import bytesequtils
# import bytesequtils

const TAG = "uarts"

Expand Down Expand Up @@ -112,17 +112,17 @@ proc read*(uart: var Uart;
result = nb

proc write*(uart: var Uart;
data: string): SzBytes {.discardable.} =
data: openArray[byte]): SzBytes {.discardable.} =

# // Write data to UART.
let bytes_written = uart_write_bytes(uart.port, data, data.len().csize_t)
let bytes_written = uart_write_bytes(uart.port, cast[cstring](data[0].unsafeAddr), data.len().csize_t)

result = bytes_written.SzBytes()

proc write*(uart: var Uart;
data: var seq[byte],
): SzBytes {.discardable.} =
# var buff = data[0..data.len]
var str = data.toStrBuf()
write(uart, str)

write(uart, data.toOpenArray(0, data.high()))

Empty file.
Empty file.
5 changes: 3 additions & 2 deletions tests/exec_tests/trouter_exec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ assert res2["result"].getInt() == 3


## Test Call 3: incorrect arguments ##
echo "\n## Call 3 ##"
echo "\n## Call 3: incorrect arguments ##"
let err_res = %* {
"jsonrpc": "2.0",
"id": 1,
Expand All @@ -58,7 +58,8 @@ var call3 = %* {
}
var res3 = rt1.route( call3 )
echo "Result 3: "
echo res3
echo res3.pretty()

assert res3["error"].kind == JObject
delete(res3["error"], "stacktrace")
assert res3 == err_res

0 comments on commit ec9460b

Please sign in to comment.