Skip to content

Commit

Permalink
move zap to CHIP build system
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Walker committed May 21, 2020
1 parent 4070921 commit 4405312
Show file tree
Hide file tree
Showing 29 changed files with 446 additions and 34 deletions.
6 changes: 5 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,10 @@ third_party/lwip/Makefile
third_party/mbedtls/Makefile
src/Makefile
src/include/Makefile
src/app/Makefile
src/app/chip-zcl/Makefile
src/app/plugin/test-unit/Makefile
src/app/plugin/test-on-off/Makefile
src/ble/Makefile
src/ble/tests/Makefile
src/crypto/Makefile
Expand All @@ -2084,8 +2088,8 @@ src/lib/core/tests/Makefile
src/lib/support/Makefile
src/lib/support/tests/Makefile
src/platform/Makefile
tests/Makefile
src/qrcodetool/Makefile
tests/Makefile
])

#
Expand Down
8 changes: 5 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ MAYBE_QRCODE_TOOL = \
$(NULL)

if !CONFIG_DEVICE_LAYER
MAYBE_QRCODE_TOOL += \
qrcodetool \
MAYBE_QRCODETOOL_SUBDIR = \
qrcodetool \
$(NULL)
endif

# Always package (e.g. for 'make dist') these subdirectories.

DIST_SUBDIRS = \
app \
include \
lwip \
system \
Expand All @@ -78,6 +79,7 @@ DIST_SUBDIRS = \
# Always build (e.g. for 'make all') these subdirectories.

SUBDIRS = \
app \
include \
lwip \
system \
Expand All @@ -87,7 +89,7 @@ SUBDIRS = \
setup_payload \
crypto \
$(MAYBE_PLATFORM_SUBDIRS) \
$(MAYBE_QRCODE_TOOL) \
$(MAYBE_QRCODETOOL_SUBDIR) \
$(NULL)

if CHIP_BUILD_TESTS
Expand Down
33 changes: 33 additions & 0 deletions src/app/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed 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.
#

#
# Description:
# This file governs what comes out of the app directory, chiefly
# the data model and application layer for the CHIP interaction
# model.
#

include $(abs_top_nlbuild_autotools_dir)/automake/pre.am

SUBDIRS = \
chip-zcl \
plugin/test-unit \
$(NULL)

# plugin/test-on-off

include $(abs_top_nlbuild_autotools_dir)/automake/post.am
34 changes: 34 additions & 0 deletions src/app/chip-zcl/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed 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.
#

#
# Description:
# This file exports the CHIP ZCL Application layer API headers
# for install and dist targets
#

include $(abs_top_nlbuild_autotools_dir)/automake/pre.am

chip_zcldir = $(includedir)/chip-zcl

chip_zcl_HEADERS = \
chip-zcl-buffer.h \
chip-zcl-codec.h \
chip-zcl-struct.h \
chip-zcl.h \
$(NULL)

include $(abs_top_nlbuild_autotools_dir)/automake/post.am
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/app/gen/gen-callback-stubs.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../api/chip-zcl.h"
#include "chip-zcl.h"

// Callback implementations

Expand Down
3 changes: 2 additions & 1 deletion src/app/plugin/binding-mock/mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ ChipZclRawBuffer_t * chipZclBufferAlloc(uint16_t allocatedLength)
buffer->endPosition = 0;
buffer->currentPosition = 0;
buffer->totalLength = allocatedLength;
return buffer;
}

/**
Expand All @@ -137,4 +138,4 @@ void chipZclBufferClear(ChipZclRawBuffer_t * buffer)
{
buffer->currentPosition = 0;
buffer->endPosition = buffer->totalLength;
}
}
7 changes: 4 additions & 3 deletions src/app/plugin/codec-simple/codec-simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* but will do ok in a typical unit test case.
*
*/
#include "../../api/chip-zcl-codec.h"
#include "chip-zcl-codec.h"

#include <memory.h>
#include <stdint.h>

Expand Down Expand Up @@ -94,9 +95,9 @@ ChipZclStatus_t chipZclCodecDecode(ChipZclRawBuffer_t * buffer, ChipZclType_t ty
case CHIP_ZCL_STRUCT_TYPE_STRING:
memcpy(&encodedLength, &(buffer->buffer[buffer->currentPosition]), 2);
buffer->currentPosition += 2;
if (encodedLength + 1 > ptrLen)
if (encodedLength > ptrLen)
return CHIP_ZCL_STATUS_FAILURE;
strncpy(ptr, &(buffer->buffer[buffer->currentPosition]), encodedLength);
memmove(ptr, &(buffer->buffer[buffer->currentPosition]), encodedLength);
buffer->currentPosition += encodedLength;
return CHIP_ZCL_STATUS_SUCCESS;
default:
Expand Down
23 changes: 23 additions & 0 deletions src/app/plugin/test-on-off/ChipZclOnOffTest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed 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 "ChipZclOnOffTest.h"

int main(void)
{
return testClusterCmdOnOff();
};
22 changes: 22 additions & 0 deletions src/app/plugin/test-on-off/ChipZclOnOffTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed 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 CHIP_ZCL_ON_OFF_TEST
#define CHIP_ZCL_ON_OFF_TEST

int testClusterCmdOnOff(void);

#endif // CHIP_ZCL_ON_OFF_TEST
File renamed without changes.
6 changes: 3 additions & 3 deletions src/app/plugin/test-on-off/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
NAME=utest-on-off
NAME=ChipZclOnOffTest
GEN=../../gen
REQUIRED_PLUGINS=../core-data-model/zcl-data-model.o ../cluster-server-on-off/on-off-server.o $(GEN)/gen-callback-stubs.o $(GEN)/gen-specs.o $(GEN)/gen-command-handler.o ../binding-mock/mock.o
REQUIRED_PLUGINS=../core-data-model/zcl-data-model.o ../cluster-server-on-off/on-off-server.o $(GEN)/gen-callback-stubs.o $(GEN)/gen-specs.o $(GEN)/gen-command-handler.o ../binding-mock/mock.o cluster-cmd-on-off-test.o

# ---------- GENERIC -------------
CC=gcc
CFLAGS="-I../../api/" "-I$(GEN)/" "-I../cluster-server-on-off/" -DCHIP_TEST
CFLAGS="-I../../chip-zcl/" "-I$(GEN)/" "-I../cluster-server-on-off/" -DCHIP_TEST

$(NAME).out: $(NAME).o $(REQUIRED_PLUGINS)
$(CC) -o $(NAME).out $(NAME).o $(REQUIRED_PLUGINS)
Expand Down
90 changes: 90 additions & 0 deletions src/app/plugin/test-on-off/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed 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.
#

#
# Description:
# This file governs what comes out of the app directory, chiefly
# the data model and application layer for the CHIP interaction
# model.
#

include $(abs_top_nlbuild_autotools_dir)/automake/pre.am

if CHIP_BUILD_TESTS

# C/C++ preprocessor option flags that will apply to all compiled
# objects in this makefile.

AM_CPPFLAGS = \
-I$(top_srcdir)/src/app/chip-zcl \
-I$(top_srcdir)/src/app/gen \
$(NULL)

lib_LIBRARIES = \
libChipZclOnOffTest.a \
$(NULL)

# plugins we need
libChipZclOnOffTest_a_SOURCES = \
../../gen/gen-callback-stubs.c \
../../gen/gen-specs.c \
../../gen/gen-command-handler.c \
../core-data-model/zcl-data-model.c \
../cluster-server-on-off/on-off-server.c \
../binding-mock/mock.c \
cluster-cmd-on-off-test.c \
ChipZclOnOffTest.c \
$(NULL)

check_PROGRAMS = \
ChipZclOnOffTest \
$(NULL)

ChipZclOnOffTest_LDADD = libChipZclOnOffTest.a

TESTS = $(check_PROGRAMS)

######################
# coverage boilerplate, TODO: move to an include
if CHIP_BUILD_COVERAGE
CLEANFILES = $(wildcard *.gcda *.gcno)

if CHIP_BUILD_COVERAGE_REPORTS
# The bundle should positively be qualified with the absolute build
# path. Otherwise, VPATH will get auto-prefixed to it if there is
# already such a directory in the non-colocated source tree.

CHIP_COVERAGE_BUNDLE = ${abs_builddir}/${PACKAGE}${NL_COVERAGE_BUNDLE_SUFFIX}
CHIP_COVERAGE_INFO = ${CHIP_COVERAGE_BUNDLE}/${PACKAGE}${NL_COVERAGE_INFO_SUFFIX}

$(CHIP_COVERAGE_BUNDLE):
$(call create-directory)

$(CHIP_COVERAGE_INFO): check-local | $(CHIP_COVERAGE_BUNDLE)
$(call generate-coverage-report,${top_builddir},*/usr/include/* */third_party/*)

coverage-local: $(CHIP_COVERAGE_INFO)

clean-local: clean-local-coverage

.PHONY: clean-local-coverage
clean-local-coverage:
-$(AM_V_at)rm -rf $(CHIP_COVERAGE_BUNDLE)

endif # CHIP_BUILD_COVERAGE_REPORTS
endif # CHIP_BUILD_COVERAGE
endif # CHIP_BUILD_TESTS
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
34 changes: 34 additions & 0 deletions src/app/plugin/test-on-off/cluster-cmd-on-off-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed 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 "ChipZclOnOffTest.h"

#include "chip-zcl.h"

#include "gen.h"

#include <stdio.h>

int testClusterCmdOnOff(void)
{
ChipZclCommandContext_t context;
context.mfgSpecific = false;
context.clusterId = CHIP_ZCL_CLUSTER_ON_OFF;
context.commandId = ZCL_ON_COMMAND_ID;
context.direction = ZCL_DIRECTION_CLIENT_TO_SERVER;
return chipZclClusterCommandParse(&context);
};
32 changes: 32 additions & 0 deletions src/app/plugin/test-on-off/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed 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.
*/

/**
* @file
* This file provides unit testing for the CHIP ZCL Command Handling
* related to the on-off-server functionality. It constructs an
* incoming message related to on-off and passes it into the CHIP
* ZCL message dispatch code
*
*/

#include "ChipZclOnOffTest.h"

int main(void)
{
return testClusterServerOnOffCmd();
}
Loading

0 comments on commit 4405312

Please sign in to comment.