Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ compile_commands.json
tools/static-analysis/reports/
*.xml
*.html

# Code coverage
*.gcda
*.gcno
coverage/
31 changes: 29 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ ifeq ($(ASAN),1)
LDFLAGS += -fsanitize=address
endif

# Add code coverage option
ifeq ($(COVERAGE),1)
CFLAGS += --coverage
LDFLAGS += --coverage
endif

## wolfSSL defines
ifeq ($(DEBUG_WOLFSSL),1)
DEF += -DDEBUG_WOLFSSL
Expand Down Expand Up @@ -190,7 +196,7 @@ vpath %.s $(dir $(SRC_ASM))

## Makefile Targets

.PHONY: build_app build_hex build_static clean run
.PHONY: build_app build_hex build_static clean run coverage

build_app: $(BUILD_DIR) $(BUILD_DIR)/$(BIN).elf
@echo Build complete.
Expand Down Expand Up @@ -238,7 +244,9 @@ clean:
$(BUILD_DIR)/*.o \
$(BUILD_DIR)/*.a \
$(BUILD_DIR)/*.sym \
$(BUILD_DIR)/*.disasm
$(BUILD_DIR)/*.disasm \
$(BUILD_DIR)/*.gcda \
$(BUILD_DIR)/*.gcno

# No prereq's here to stop from rebuilding with different options
run:
Expand All @@ -247,3 +255,22 @@ ifeq (,$(wildcard $(BUILD_DIR)/$(BIN).elf))
else
$(BUILD_DIR)/$(BIN).elf
endif

# Coverage target: build with coverage, run tests, and generate report
coverage:
@echo "Building with coverage enabled..."
$(MAKE) clean
$(MAKE) COVERAGE=1 DEBUG=1
Comment thread
bigbrett marked this conversation as resolved.
Outdated
@echo "Running tests..."
@if [ ! -f $(BUILD_DIR)/$(BIN).elf ]; then \
echo "Error: $(BUILD_DIR)/$(BIN).elf not found. Build failed."; \
exit 1; \
fi
$(BUILD_DIR)/$(BIN).elf
Comment thread
bigbrett marked this conversation as resolved.
@echo "Generating coverage report..."
gcovr --root .. \
--filter 'src/.*' \
--filter 'wolfhsm/.*' \
--html-details $(BUILD_DIR)/coverage.html \
--print-summary
@echo "Coverage report generated at $(BUILD_DIR)/coverage.html"
64 changes: 64 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,67 @@ IMG_MGR ECC P256 Test completed successfully!
IMG_MGR AES128 CMAC Test completed successfully!
IMG_MGR RSA2048 Test completed successfully!
```

## Code Coverage

The test suite supports code coverage analysis using gcovr. To generate coverage reports:

**Note**: The coverage directory must exist before generating reports. The `make coverage` target creates this automatically, but if running gcovr manually, create it first with:
```bash
mkdir -p ../coverage
```

### Running Coverage

Use the convenient coverage target:
```bash
make coverage
```

This will:
1. Clean previous build artifacts
2. Rebuild with coverage instrumentation enabled
3. Run the test suite
4. Generate an HTML coverage report

The coverage report will be generated at `../coverage/index.html`.

### Manual Coverage Workflow

Alternatively, you can run coverage manually:

```bash
# Build with coverage enabled
make clean
make COVERAGE=1 DEBUG=1

# Run tests
make run

# Create coverage directory and generate report (from repository root)
cd ..
mkdir -p coverage
gcovr --root . \
--filter 'src/.*' \
--filter 'wolfhsm/.*' \
--html-details coverage/index.html \
--print-summary
```

### Coverage Options

You can customize the coverage report generation:

```bash
# Generate XML format (for CI/CD)
gcovr --root . --filter 'src/.*' --filter 'wolfhsm/.*' --xml coverage.xml

# Generate JSON format
gcovr --root . --filter 'src/.*' --filter 'wolfhsm/.*' --json coverage.json

# Include branch coverage
gcovr --root . --filter 'src/.*' --filter 'wolfhsm/.*' --branches --print-summary

# Set minimum coverage threshold (fails if below 80%)
gcovr --root . --filter 'src/.*' --filter 'wolfhsm/.*' --fail-under-line 80
```
6 changes: 3 additions & 3 deletions wolfhsm/wh_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1047,9 +1047,9 @@ int wh_Client_KeyUnwrapAndCacheRequest(whClientContext* ctx,
* key.
* @return int Returns 0 on success, or a negative error code on failure.
*/
int wh_Client_UnrapKeyAndCacheResponse(whClientContext* ctx,
enum wc_CipherType cipherType,
uint16_t* keyIdOut);
int wh_Client_KeyUnwrapAndCacheResponse(whClientContext* ctx,
Comment thread
bigbrett marked this conversation as resolved.
enum wc_CipherType cipherType,
uint16_t* keyIdOut);

/* Counter functions */
int wh_Client_CounterInitRequest(whClientContext* c, whNvmId counterId,
Expand Down
6 changes: 1 addition & 5 deletions wolfhsm/wh_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,8 @@ typedef whDmaOper whServerDmaOper;
typedef whDmaFlags whServerDmaFlags;
typedef whDmaAddr whServerDmaAddr;
typedef whDmaAddrList whServerDmaAddrList;

#ifdef WOLFHSM_CFG_DMA_CUSTOM_CLIENT_COPY
typedef enum {
WH_DMA_COPY_OPER_CLIENT_READ = 0,
WH_DMA_COPY_OPER_CLIENT_WRITE = 1,
} whServerDmaCopyOper;
typedef whDmaCopyOper whServerDmaCopyOper;
Comment thread
bigbrett marked this conversation as resolved.
#endif /* WOLFHSM_CFG_DMA_CUSTOM_CLIENT_COPY */

/* DMA callbacks invoked internally by wolfHSM before and after every client
Expand Down