Skip to content

Commit

Permalink
test: Add zephyr test
Browse files Browse the repository at this point in the history
Add Zephyr system to libmetal test.

Signed-off-by: Wendy Liang <jliang@xilinx.com>
  • Loading branch information
wjliang committed Dec 28, 2017
1 parent c037f13 commit 4b1380c
Show file tree
Hide file tree
Showing 8 changed files with 674 additions and 46 deletions.
106 changes: 60 additions & 46 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,70 @@ collect (PROJECT_LIB_HEADERS metal-test.h)
collect (PROJECT_LIB_TESTS version.c)
collect (PROJECT_LIB_TESTS metal-test.c)

collector_list (_list PROJECT_INC_DIRS)
include_directories (${_list} ${CMAKE_CURRENT_SOURCE_DIR})
collector_list (_hdirs PROJECT_INC_DIRS)
include_directories (${_hdirs} ${CMAKE_CURRENT_SOURCE_DIR})

collector_list (_list PROJECT_LIB_DIRS)
link_directories (${_list})
collector_list (_ldirs PROJECT_LIB_DIRS)
link_directories (${_ldirs})

collector_list (_deps PROJECT_LIB_DEPS)

collector_list (_list PROJECT_LIB_TESTS)

if (WITH_SHARED_LIB)
set (_lib ${PROJECT_NAME}-shared)
add_executable (test-${_lib} ${_list})
target_link_libraries (test-${_lib} ${_deps} ${_lib})
install (TARGETS test-${_lib} RUNTIME DESTINATION bin)
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (test-${_lib} PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
add_dependencies (test-${_lib} ${PROJECT_NAME}-shared)
if (WITH_TESTS_EXEC)
add_test (test-${_lib} test-${_lib})
endif (WITH_TESTS_EXEC)
endif (WITH_SHARED_LIB)

if (WITH_STATIC_LIB)
get_property (_linker_options GLOBAL PROPERTY TEST_LINKER_OPTIONS)
set (_lib ${PROJECT_NAME}-static)
add_executable (test-${_lib} ${_list})
target_link_libraries (test-${_lib} -Wl,-Map=test-${_lib}.map ${_linker_options} -Wl,--start-group ${_lib} ${_deps} -Wl,--end-group)
install (TARGETS test-${_lib} RUNTIME DESTINATION bin)
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (test-${_lib} PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
add_dependencies (test-${_lib} ${PROJECT_NAME}-static)
if (WITH_TESTS_EXEC)
add_test (test-${_lib} test-${_lib})
endif (WITH_TESTS_EXEC)
endif (WITH_STATIC_LIB)

collector_list (_headers PROJECT_HDR_TESTS)
foreach (INCLUDE ${_headers})
string (REGEX REPLACE "[^a-zA-Z0-9]+" "-" _f ${INCLUDE})
configure_file (metal-header-template.c ${_f}.c)
list (APPEND _flist "${CMAKE_CURRENT_BINARY_DIR}/${_f}")
endforeach (INCLUDE)
add_library (metal-headers STATIC ${_flist})

collector_list (_list PROJECT_HDR_TESTS)
collector_list (_srcs PROJECT_LIB_TESTS)

if (WITH_ZEPHYR)
set (_tfiles "")
foreach (f ${_srcs})
list(APPEND _tfiles "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
endforeach(f)
target_sources(app PRIVATE ${_tfiles})
target_include_directories (app PRIVATE ${_hdirs} ${CMAKE_CURRENT_SOURCE_DIR})
set (_eldflags "")
foreach (d ${_ldirs})
list (APPEND _eldflags "-L${d}")
endforeach(d)
add_dependencies(app metal)
list (APPEND _deps -lmetal)
target_link_libraries(app LINK_INTERFACE_LIBRARIES "${_eldflags}" ${_deps})
target_compile_options (app PRIVATE -DNOT_HAVE_STRERROR)
else (WITH_ZEPHYR)
if(WITH_SHARED_LIB)
set (_lib ${PROJECT_NAME}-shared)
add_executable (test-${_lib} ${_srcs})
target_link_libraries (test-${_lib} ${_deps} ${_lib})
install (TARGETS test-${_lib} RUNTIME DESTINATION bin)
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (test-${_lib} PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
add_dependencies (test-${_lib} ${PROJECT_NAME}-shared)
if (WITH_TESTS_EXEC)
add_test (test-${_lib} test-${_lib})
endif (WITH_TESTS_EXEC)
endif (WITH_SHARED_LIB)

if (WITH_STATIC_LIB)
get_property (_linker_options GLOBAL PROPERTY TEST_LINKER_OPTIONS)
set (_lib ${PROJECT_NAME}-static)
add_executable (test-${_lib} ${_srcs})
target_link_libraries (test-${_lib} -Wl,-Map=test-${_lib}.map ${_linker_options} -Wl,--start-group ${_lib} ${_deps} -Wl,--end-group)
install (TARGETS test-${_lib} RUNTIME DESTINATION bin)
if (PROJECT_EC_FLAGS)
string(REPLACE " " ";" _ec_flgs ${PROJECT_EC_FLAGS})
target_compile_options (test-${_lib} PUBLIC ${_ec_flgs})
endif (PROJECT_EC_FLAGS)
add_dependencies (test-${_lib} ${PROJECT_NAME}-static)
if (WITH_TESTS_EXEC)
add_test (test-${_lib} test-${_lib})
endif (WITH_TESTS_EXEC)
endif (WITH_STATIC_LIB)

collector_list (_headers PROJECT_HDR_TESTS)
foreach (INCLUDE ${_headers})
string (REGEX REPLACE "[^a-zA-Z0-9]+" "-" _f ${INCLUDE})
configure_file (metal-header-template.c ${_f}.c)
list (APPEND _flist "${CMAKE_CURRENT_BINARY_DIR}/${_f}")
endforeach (INCLUDE)
add_library (metal-headers STATIC ${_flist})
endif (WITH_ZEPHYR)

# vim: expandtab:ts=2:sw=2:smartindent
11 changes: 11 additions & 0 deletions test/system/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
collect (PROJECT_LIB_TESTS main.c)
collect (PROJECT_LIB_TESTS alloc.c)
collect (PROJECT_LIB_TESTS irq.c)
collect (PROJECT_LIB_TESTS mutex.c)
collect (PROJECT_LIB_TESTS atomic.c)

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE})
add_subdirectory(${PROJECT_MACHINE})
endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE})

# vim: expandtab:ts=2:sw=2:smartindent
53 changes: 53 additions & 0 deletions test/system/zephyr/alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2016, Xilinx Inc. and Contributors. 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 Xilinx 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 AND CONTRIBUTORS "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 OR CONTRIBUTORS 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.
*/

#include <stdlib.h>

#include <metal/alloc.h>
#include <metal/log.h>
#include <metal/sys.h>
#include <misc/printk.h>
#include "metal-test-internal.h"

static int alloc(void)
{
void *ptr;

ptr = metal_allocate_memory(1000);
if (!ptr) {
metal_log(METAL_LOG_DEBUG, "failed to allocate memmory\n");
return errno;
}

metal_free_memory(ptr);

return 0;
}
METAL_ADD_TEST(alloc);
58 changes: 58 additions & 0 deletions test/system/zephyr/atomic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2016, Xilinx Inc. and Contributors. 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 Xilinx 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 AND CONTRIBUTORS "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 OR CONTRIBUTORS 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.
*/

#include <stdlib.h>

#include <metal/atomic.h>
#include <metal/log.h>
#include <metal/sys.h>
#include "metal-test-internal.h"

static const int atomic_test_count = 1000;

static int atomic(void)
{
atomic_int counter = ATOMIC_VAR_INIT(0);
int value, error=0, i;

for (i = 0; i < atomic_test_count; i++) {
atomic_fetch_add(&counter, 1);
}

value = atomic_load(&counter);
value -= atomic_test_count;
if (value) {
metal_log(METAL_LOG_DEBUG, "counter mismatch, delta = %d\n", value);
error = -1;
}

return error;
}
METAL_ADD_TEST(atomic);
Loading

0 comments on commit 4b1380c

Please sign in to comment.