system: add libuv port for NuttX
This commit is contained in:
parent
74c506b4d1
commit
18158ed271
1
system/libuv/.gitignore
vendored
Normal file
1
system/libuv/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/Kconfig
|
7308
system/libuv/0001-initial-libuv-port-to-nuttx.patch
Normal file
7308
system/libuv/0001-initial-libuv-port-to-nuttx.patch
Normal file
File diff suppressed because it is too large
Load Diff
32
system/libuv/Make.defs
Normal file
32
system/libuv/Make.defs
Normal file
@ -0,0 +1,32 @@
|
||||
############################################################################
|
||||
# system/libuv/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Set up build configuration and environment
|
||||
|
||||
LIBUV_DIR := $(APPDIR)/system/libuv
|
||||
|
||||
CONFIG_LIBUV_URL ?= "https://github.com/libuv/libuv/archive"
|
||||
CONFIG_LIBUV_VERSION ?= 1.38.1
|
||||
CONFIG_LIBUV_TARBALL ?= v$(CONFIG_LIBUV_VERSION).zip
|
||||
|
||||
LIBUV_UNPACKNAME := libuv-$(CONFIG_LIBUV_VERSION)
|
||||
LIBUV_UNPACKDIR := $(LIBUV_DIR)/$(LIBUV_UNPACKNAME)
|
||||
|
||||
include $(wildcard $(APPDIR)/system/libuv/*/Make.defs)
|
23
system/libuv/Makefile
Normal file
23
system/libuv/Makefile
Normal file
@ -0,0 +1,23 @@
|
||||
############################################################################
|
||||
# system/libuv/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
MENUDESC = "libuv async i/o Library"
|
||||
|
||||
include $(APPDIR)/Directory.mk
|
123
system/libuv/libuv/Kconfig
Normal file
123
system/libuv/libuv/Kconfig
Normal file
@ -0,0 +1,123 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config LIBUV
|
||||
bool "libuv asynchronous I/O Library"
|
||||
default n
|
||||
---help---
|
||||
Enable build for libuv asynchronous I/O Library
|
||||
|
||||
if LIBUV
|
||||
|
||||
config LIBUV_NPOLLWAITERS
|
||||
int "Number of uv loop poll waiters"
|
||||
default 8
|
||||
---help---
|
||||
Maximum number of events a loop can wait on.
|
||||
|
||||
config LIBUV_ASYNC
|
||||
bool "libuv async support"
|
||||
default n
|
||||
select EVENT_FD
|
||||
select EVENT_FD_POLL
|
||||
---help---
|
||||
Enable async support in libuv.
|
||||
Eventfd is required for this feature.
|
||||
|
||||
config LIBUV_TIMER
|
||||
bool "libuv software timers support"
|
||||
default n
|
||||
select CLOCK_MONOTONIC
|
||||
---help---
|
||||
Enable software timers support in libuv.
|
||||
|
||||
config LIBUV_TIMER_NUTTX
|
||||
bool "optimized software timers"
|
||||
default y
|
||||
depends on LIBUV_TIMER
|
||||
---help---
|
||||
Replace default libuv timer with optimized implementation
|
||||
with low memory footprint.
|
||||
|
||||
config LIBUV_STREAM
|
||||
bool "libuv stream support"
|
||||
default n
|
||||
---help---
|
||||
Enable stream support in libuv.
|
||||
|
||||
config LIBUV_STREAM_READ_SIZE
|
||||
int "Stream read buffer size"
|
||||
default 128
|
||||
depends on LIBUV_STREAM
|
||||
---help---
|
||||
Defines the size of buffer used for stream reads.
|
||||
|
||||
config LIBUV_FS
|
||||
bool "libuv FS support"
|
||||
default n
|
||||
---help---
|
||||
Enable libuv FS support.
|
||||
This feature may require LIBUV_WQ to support async FS operations.
|
||||
|
||||
config LIBUV_FS_POLL
|
||||
bool "libuv fs-poll support"
|
||||
default n
|
||||
select LIBUV_FS
|
||||
select LIBUV_TIMER
|
||||
---help---
|
||||
Enable libuv uv_fs_poll_*() API.
|
||||
|
||||
config LIBUV_NET
|
||||
bool
|
||||
|
||||
config LIBUV_TCP
|
||||
bool "libuv TCP support"
|
||||
default n
|
||||
depends on NET_TCP
|
||||
depends on NET_TCPBACKLOG
|
||||
select LIBUV_STREAM
|
||||
select LIBUV_NET
|
||||
---help---
|
||||
Enable TCP support in libuv.
|
||||
NET_TCPBACKLOG is required to poll on accept().
|
||||
|
||||
config LIBUV_WQ
|
||||
bool "libuv workqueue support"
|
||||
default n
|
||||
select LIBUV_ASYNC
|
||||
---help---
|
||||
Enable workqueue support in libuv
|
||||
|
||||
config LIBUV_WQ_THREADS_COUNT
|
||||
int "libuv workqueue thread count"
|
||||
depends on LIBUV_WQ
|
||||
default 1
|
||||
---help---
|
||||
Specify worker thread count shared between all uv loops
|
||||
|
||||
config LIBUV_LOOP_WATCHERS
|
||||
bool "libuv loop watchers support"
|
||||
default n
|
||||
---help---
|
||||
Enable loop watchers support in libuv (idle,prepare and check)
|
||||
|
||||
config LIBUV_CONTEXT
|
||||
bool "Use static context for loops"
|
||||
default y
|
||||
---help---
|
||||
Modify libuv API to remove static memory usage.
|
||||
User must call "uv_context_init()" before any other libuv API and
|
||||
must call "uv_library_shutdown()" when done.
|
||||
This is required for flat memory builds else some libuv structures
|
||||
will be shared between processes which can lead to inconsistency.
|
||||
This option disable support for uv_default_loop() API.
|
||||
|
||||
config LIBUV_LOW_FOOTPRINT
|
||||
bool "Reduce libuv memory usage"
|
||||
default y
|
||||
---help---
|
||||
Enable optimizations to reduce libuv memory usage
|
||||
|
||||
endif # LIBUV
|
31
system/libuv/libuv/Make.defs
Normal file
31
system/libuv/libuv/Make.defs
Normal file
@ -0,0 +1,31 @@
|
||||
############################################################################
|
||||
# system/libuv/libuv/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_LIBUV),)
|
||||
CONFIGURED_APPS += $(APPDIR)/system/libuv/libuv
|
||||
|
||||
# Enable <uv.h> include.
|
||||
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \
|
||||
$(APPDIR)/system/libuv/$(LIBUV_UNPACKNAME)/include}
|
||||
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" \
|
||||
$(APPDIR)/system/libuv/$(LIBUV_UNPACKNAME)/include}
|
||||
|
||||
endif
|
121
system/libuv/libuv/Makefile
Normal file
121
system/libuv/libuv/Makefile
Normal file
@ -0,0 +1,121 @@
|
||||
############################################################################
|
||||
# system/libuv/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
LIBUV_PATCHS ?= $(sort $(wildcard $(LIBUV_DIR)/000*.patch))
|
||||
WGET ?= wget
|
||||
UNPACK ?= unzip -q
|
||||
|
||||
$(LIBUV_DIR)/$(CONFIG_LIBUV_TARBALL):
|
||||
@echo "Downloading: $(CONFIG_LIBUV_TARBALL)"
|
||||
$(Q) $(WGET) $(CONFIG_LIBUV_URL)/$(CONFIG_LIBUV_TARBALL) \
|
||||
-O $(LIBUV_DIR)/$(CONFIG_LIBUV_TARBALL)
|
||||
|
||||
$(LIBUV_UNPACKDIR): $(LIBUV_DIR)/$(CONFIG_LIBUV_TARBALL)
|
||||
@echo "Unpacking: $(CONFIG_LIBUV_TARBALL) -> $(LIBUV_UNPACKDIR)"
|
||||
$(call DELDIR, $(LIBUV_UNPACKDIR))
|
||||
$(Q) unzip -q -d "$(LIBUV_DIR)" "$(LIBUV_DIR)/$(CONFIG_LIBUV_TARBALL)"
|
||||
$(Q) cat $(LIBUV_PATCHS) | \
|
||||
patch -s -N -d $(LIBUV_UNPACKDIR) -p1
|
||||
$(Q) touch $(LIBUV_UNPACKDIR)
|
||||
|
||||
# Build libuv library
|
||||
|
||||
CFLAGS += -I$(LIBUV_UNPACKDIR)/src
|
||||
CFLAGS += -I$(LIBUV_UNPACKDIR)/src/unix
|
||||
CFLAGS += -D__NUTTX__
|
||||
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/core.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/poll.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/loop.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/thread.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/no-proctitle.c
|
||||
|
||||
ifeq ($(CONFIG_DEV_URANDOM),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/random-devurandom.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/random.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_LOOP_WATCHERS),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/loop-watcher.c
|
||||
endif
|
||||
|
||||
# FIXME signal does not work yet
|
||||
ifeq ($(CONFIG_LIBUV_SIGNAL),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/signal.c
|
||||
endif
|
||||
|
||||
# FIXME process does not work yet
|
||||
ifeq ($(CONFIG_LIBUV_PROCESS),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/process.c
|
||||
endif
|
||||
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/nuttx.c
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_STREAM),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/nuttx_stream.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_TCP),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/nuttx_tcp.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_WQ),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/nuttx_threadpool.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_ASYNC),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/async.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_FS),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/fs.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_FS_POLL),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/fs-poll.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_TIMER),y)
|
||||
ifeq ($(CONFIG_LIBUV_TIMER_NUTTX),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/unix/nuttx_timer.c
|
||||
else
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/timer.c
|
||||
endif
|
||||
endif
|
||||
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/uv-common.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/strscpy.c
|
||||
|
||||
ifeq ($(CONFIG_LIBUV_NET),y)
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/src/inet.c
|
||||
endif
|
||||
|
||||
context:: $(LIBUV_UNPACKDIR)
|
||||
|
||||
clean::
|
||||
$(call DELFILE, $(OBJS))
|
||||
|
||||
distclean::
|
||||
$(call DELDIR, $(LIBUV_UNPACKDIR))
|
||||
$(call DELFILE, $(LIBUV_DIR)/$(CONFIG_LIBUV_TARBALL))
|
||||
|
||||
include $(APPDIR)/Application.mk
|
35
system/libuv/tests/Kconfig
Normal file
35
system/libuv/tests/Kconfig
Normal file
@ -0,0 +1,35 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
menuconfig LIBUV_UNIT_TESTS
|
||||
tristate "libuv unit-tests command"
|
||||
default n
|
||||
depends on LIBUV
|
||||
select LIBUV_TIMER
|
||||
select LIBUV_ASYNC
|
||||
select LIBUV_WQ
|
||||
select LIBUV_LOOP_WATCHERS
|
||||
select LIBUV_CONTEXT
|
||||
---help---
|
||||
Add executable that runs all libuv unit-tests.
|
||||
|
||||
if LIBUV_UNIT_TESTS
|
||||
|
||||
config LIBUV_UNIT_TESTS_PROGNAME
|
||||
string "libuv unit-tests program name"
|
||||
default "libuvtest"
|
||||
---help---
|
||||
This is the name of the program that will be used when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config LIBUV_UNIT_TESTS_PRIORITY
|
||||
int "libuv unit-tests task priority"
|
||||
default 100
|
||||
|
||||
config LIBUV_UNIT_TESTS_STACKSIZE
|
||||
int "libuv unit-tests stack size"
|
||||
default DEFAULT_TASK_STACKSIZE
|
||||
|
||||
endif # LIBUV_UNIT_TESTS
|
23
system/libuv/tests/Make.defs
Normal file
23
system/libuv/tests/Make.defs
Normal file
@ -0,0 +1,23 @@
|
||||
############################################################################
|
||||
# system/libuv/tests/Make.defs
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_LIBUV_UNIT_TESTS),)
|
||||
CONFIGURED_APPS += $(APPDIR)/system/libuv/tests
|
||||
endif
|
70
system/libuv/tests/Makefile
Normal file
70
system/libuv/tests/Makefile
Normal file
@ -0,0 +1,70 @@
|
||||
############################################################################
|
||||
# system/libuv/tests/Makefile
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# libuv unit-tests command
|
||||
|
||||
PROGNAME := $(CONFIG_LIBUV_UNIT_TESTS_PROGNAME)
|
||||
PRIORITY := $(CONFIG_LIBUV_UNIT_TESTS_PRIORITY)
|
||||
STACKSIZE := $(CONFIG_LIBUV_UNIT_TESTS_STACKSIZE)
|
||||
MODULE := $(CONFIG_LIBUV_UNIT_TESTS)
|
||||
|
||||
# Files
|
||||
|
||||
MAINSRC := test_main.c
|
||||
CSRCS += runner-nuttx.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/runner.c
|
||||
|
||||
# Tests
|
||||
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-loop-time.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-async.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-ip4-addr.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-active.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-idle.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-timer.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-timer-from-check.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-timer-again.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-threadpool.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-walk-handles.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-poll-close.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-loop-close.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-loop-stop.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-tcp-read-stop.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-tcp-write-after-connect.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-fs-copyfile.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-fs-poll.c
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/test-random.c
|
||||
|
||||
# Test helpers
|
||||
|
||||
CSRCS += $(LIBUV_UNPACKDIR)/test/echo-server.c
|
||||
|
||||
# Compilation flags
|
||||
|
||||
CFLAGS += -I$(LIBUV_UNPACKDIR)/test
|
||||
CFLAGS += -I.
|
||||
CFLAGS += -D__NUTTX__
|
||||
|
||||
clean::
|
||||
$(call DELFILE, $(OBJS))
|
||||
|
||||
include $(APPDIR)/Application.mk
|
152
system/libuv/tests/runner-nuttx.c
Normal file
152
system/libuv/tests/runner-nuttx.c
Normal file
@ -0,0 +1,152 @@
|
||||
/****************************************************************************
|
||||
* system/libuv/tests/runner-nuttx.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <debug.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <uv.h>
|
||||
#include "runner-nuttx.h"
|
||||
#include "runner.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t get_time_ms(void);
|
||||
static void *process_launcher(void *arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t get_time_ms(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (uint32_t)(((uint64_t) ts.tv_sec) * 1000 +
|
||||
(ts.tv_nsec / 1000 / 1000));
|
||||
}
|
||||
|
||||
static void *process_launcher(void *arg)
|
||||
{
|
||||
process_info_t *p = (process_info_t *)arg;
|
||||
p->task->main();
|
||||
sem_post(&p->sem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void platform_init(int argc, char **argv)
|
||||
{
|
||||
}
|
||||
|
||||
int process_start(task_entry_t *task, process_info_t *p, int is_helper)
|
||||
{
|
||||
if (is_helper)
|
||||
{
|
||||
printf("===> START HELPER %s/%s\n",
|
||||
task->task_name, task->process_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("===> START TEST %s\n", task->task_name);
|
||||
}
|
||||
|
||||
p->task = task;
|
||||
|
||||
if (sem_init(&p->sem, 0, 0))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pthread_create(&p->tid, NULL, process_launcher, p) != 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to start process %s\n", task->process_name);
|
||||
sem_destroy(&p->sem);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int process_wait(process_info_t *vec, int n, int timeout)
|
||||
{
|
||||
uv_time_t time = get_time_ms();
|
||||
|
||||
while (--n >= 0)
|
||||
{
|
||||
int found = 0;
|
||||
while ((uv_time_t)(get_time_ms()-time) < (uv_time_t)timeout)
|
||||
{
|
||||
if (sem_trywait(&vec[n].sem) == 0)
|
||||
{
|
||||
FAR pthread_addr_t value;
|
||||
pthread_join(vec[n].tid, &value);
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (errno != EAGAIN)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Let NuttX update time */
|
||||
|
||||
usleep(100 * 1000);
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
/* Timeout or error */
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int process_terminate(process_info_t *p)
|
||||
{
|
||||
/* TODO */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int process_reap(process_info_t *p)
|
||||
{
|
||||
/* TODO */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void process_cleanup(process_info_t *p)
|
||||
{
|
||||
}
|
46
system/libuv/tests/runner-nuttx.h
Normal file
46
system/libuv/tests/runner-nuttx.h
Normal file
@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
* system/libuv/tests/runner-nuttx.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef TEST_RUNNER_NUTTX_H
|
||||
#define TEST_RUNNER_NUTTX_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
struct task_entry_s;
|
||||
|
||||
struct process_info_s
|
||||
{
|
||||
pthread_t tid;
|
||||
sem_t sem;
|
||||
struct task_entry_s *task;
|
||||
};
|
||||
|
||||
typedef struct process_info_s process_info_t;
|
||||
|
||||
#endif /* TEST_RUNNER_NUTTX_H */
|
56
system/libuv/tests/test_main.c
Normal file
56
system/libuv/tests/test_main.c
Normal file
@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
* system/libuv/tests/test_main.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "runner.h"
|
||||
#include "test-list.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char **argv)
|
||||
{
|
||||
platform_init(argc, argv);
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1], "--list") == 0)
|
||||
{
|
||||
print_tests(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
return run_test_part(argv[1], argv[2]);
|
||||
}
|
||||
}
|
||||
|
||||
return run_tests(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user