Skip to content

Commit

Permalink
add nedtrie for function mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
gijzelaerr committed Feb 16, 2018
1 parent 060689d commit a108ff1
Show file tree
Hide file tree
Showing 12 changed files with 3,334 additions and 1,088 deletions.
30 changes: 30 additions & 0 deletions LICENSE
@@ -1,3 +1,33 @@

files: src/static/nedtrie.h
license: Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.


files: *
license: BSD 3 clause

Copyright (c) 2017 Gijs Molenaar
All rights reserved.

Expand Down
13 changes: 13 additions & 0 deletions generate/filters.py
Expand Up @@ -217,6 +217,19 @@ def initialise_test(type_, identifier):
return "{} {} = NULL_PTR; /* todo: probably requires finetuning */".format(type_, identifier)


def initialise_verify(type_, identifier):
"""used to initialise the verification variables used in tests, typically set to something else than the test
initialise variables :)"""
if type_ in ("CK_SESSION_HANDLE", "CK_SLOT_ID", "CK_OBJECT_HANDLE", "CK_ULONG", "CK_MECHANISM_TYPE", "CK_USER_TYPE", "CK_FLAGS", "CK_BBOOL"):
return "{} {} = 0;".format(type_, identifier)
elif type_ in type_test_templates:
return type_test_templates[type_].format(identifier=identifier, type_=type_)
elif not type_.endswith("_PTR"):
return "{} {} = NULL; /* todo: probably requires finetuning */".format(type_, identifier)
else:
return "{} {} = NULL_PTR; /* todo: probably requires finetuning */".format(type_, identifier)


def free(type_, identifier):
if type_ == "CK_ATTRIBUTE_PTR":
return "free({});\n".format(identifier)
Expand Down
4 changes: 3 additions & 1 deletion generate/generate.py
Expand Up @@ -10,7 +10,8 @@
from asn1ate.sema import dependency_sort
from jinja2 import Environment, FileSystemLoader, StrictUndefined

from filters import combined_args, under, extract_args, initialise, free, is_pointer, depointerize, initialise_test, is_notify
from filters import combined_args, under, extract_args, initialise, free, is_pointer, depointerize, initialise_test,\
is_notify, initialise_verify


# not required in pkcs11 or not exposed
Expand Down Expand Up @@ -101,6 +102,7 @@ def main(pickle_file):
env.globals['extract_args'] = extract_args
env.globals['initialise'] = initialise
env.globals['initialise_test'] = initialise_test
env.globals['initialise_verify'] = initialise_verify
env.globals['free'] = free

data = load_data(pickle_file)
Expand Down
5 changes: 2 additions & 3 deletions generate/templates/test/test_pack.c
Expand Up @@ -29,8 +29,7 @@ void test_pack_{{ f.type_name|under }}(void **state) {
assert_int_equal(status, CKR_OK);

{% for type_, pointerized, identifier, other in extract_args(f, o) -%}
//{{ initialise(type_, identifier + "_unpack") }}
{{ type_ }} {{ identifier }}_unpack;
{{ initialise_verify(type_, identifier + "_unpack") }}
{% endfor %}

status = unpack_{{ f.type_name|under }}(
Expand Down Expand Up @@ -61,7 +60,7 @@ void test_pack_{{ f.type_name|under }}(void **state) {

int main(void) {
const struct CMUnitTest tests[] = {
{% for f in functions[:2] %}
{% for f in functions[:4] %}
cmocka_unit_test(test_pack_{{ f.type_name|under }}){% if not loop.last %},{% endif -%}
{% endfor %}

Expand Down
10 changes: 7 additions & 3 deletions src/CMakeLists.txt
Expand Up @@ -14,7 +14,9 @@ set(LIB_H
static/util.h
static/returncodes.h
static/derput.h
static/derget.h)
static/derget.h
static/nedtrie.h
)

set(LIB_SRC
generated/pack.c
Expand All @@ -39,10 +41,11 @@ enable_testing()

add_executable(client.test generated/test/test_client.c)
add_executable(pack.test generated/test/test_pack.c)

#add_executable(server.test generated/test/test_server.c)

add_dependencies(client.test client.test)
add_dependencies(pack.test pack.test)
#add_dependencies(server.test server.test)


set(KEEHIVE_TEST_LINK_LIRARIES
Expand All @@ -52,7 +55,8 @@ set(KEEHIVE_TEST_LINK_LIRARIES

target_link_libraries(client.test keehive ${KEEHIVE_TEST_LINK_LIRARIES})
target_link_libraries(pack.test keehive ${KEEHIVE_TEST_LINK_LIRARIES})

#target_link_libraries(server.test keehive ${KEEHIVE_TEST_LINK_LIRARIES})

add_test(client.test client.test)
add_test(pack.test pack.test)
#add_test(server.test server.test)

0 comments on commit a108ff1

Please sign in to comment.