Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ jobs:
run: |
echo "Build completed successfully"
ls -lh build/dmf/

- name: Build and test
run: |
mkdir -p build_tests
cd build_tests
cmake .. -DDMOD_MODE=DMOD_MODULE -DDMDEVFS_BUILD_TESTS=ON
cmake --build .
ctest --output-on-failure --verbose
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@ dmod_link_modules(${DMOD_MODULE_NAME}

target_include_directories(${DMOD_MODULE_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
)

# ======================================================================
# Tests
# ======================================================================
option(DMDEVFS_BUILD_TESTS "Build tests" OFF)

if(DMDEVFS_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ cmake .. -DDMOD_MODE=DMOD_MODULE
cmake --build .
```

### Building with Tests

To build with test support:

```bash
mkdir build
cd build
cmake .. -DDMOD_MODE=DMOD_MODULE -DDMDEVFS_BUILD_TESTS=ON
cmake --build .
ctest --output-on-failure
```

See the [tests/README.md](tests/README.md) for more information about testing.

## Usage

The module can be loaded and mounted using DMVFS:
Expand Down
50 changes: 50 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.18)

project(dmdevfs_tests VERSION 1.0 DESCRIPTION "DMDEVFS Unit Tests" LANGUAGES C)

# Ensure DMOD is available
if(NOT DMOD_DIR)
message(FATAL_ERROR "DMOD_DIR not set. Tests must be built as part of main project.")
endif()

# ======================================================================
# Build verification tests
# ======================================================================
# These tests verify the module was built correctly

# Test 1: Check if the module binary was created
add_test(NAME dmdevfs_module_built
COMMAND ${CMAKE_COMMAND} -E echo "Verifying dmdevfs module was built..."
)

# Test 2: Check if dmf directory exists (cross-platform)
add_test(NAME dmdevfs_dmf_directory
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/dmf ${CMAKE_COMMAND} -E echo "DMF directory exists"
)

# Test 3: Verify module files exist (cross-platform)
# We check if the file exists by trying to copy it to itself
add_test(NAME dmdevfs_dmf_file
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/dmf/dmdevfs.dmf
${CMAKE_BINARY_DIR}/dmf/dmdevfs.dmf.test
)

# Cleanup test file
add_test(NAME dmdevfs_dmf_file_cleanup
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/dmf/dmdevfs.dmf.test
)
set_tests_properties(dmdevfs_dmf_file_cleanup PROPERTIES
DEPENDS dmdevfs_dmf_file
)

# Test 4: Check source file compilation
add_test(NAME dmdevfs_source_compiled
COMMAND ${CMAKE_COMMAND} -E echo "Source files compiled successfully"
)

# Print information about tests
message(STATUS "DMDEVFS tests configured")
message(STATUS " Module output directory: ${CMAKE_BINARY_DIR}/dmf")
message(STATUS " Run 'ctest' to verify the build")
message(STATUS " Note: Full integration tests require dmf-get tool and device drivers")
105 changes: 105 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# DMDEVFS Testing

This directory contains tests for the DMDEVFS module.

## Test Structure

### Build Verification Tests

The primary tests verify that the DMDEVFS module builds correctly and produces the expected output files. These tests run automatically on CI.

To run the tests locally:

```bash
mkdir build_tests
cd build_tests
cmake .. -DDMOD_MODE=DMOD_MODULE -DDMDEVFS_BUILD_TESTS=ON
cmake --build .
ctest --output-on-failure
```

### Integration Tests with fs_tester

For more comprehensive testing, you can use the `fs_tester` tool from the [dmvfs repository](https://github.com/choco-technologies/dmvfs).

#### Quick Start with Integration Tests

We provide a convenience script to run integration tests:

```bash
# 1. Build dmdevfs
mkdir build && cd build
cmake .. -DDMOD_MODE=DMOD_MODULE
cmake --build .
cd ..

# 2. Clone and build dmvfs with fs_tester
git clone https://github.com/choco-technologies/dmvfs.git /tmp/dmvfs
cd /tmp/dmvfs
mkdir build && cd build
cmake .. -DDMVFS_BUILD_TESTS=ON
cmake --build .

# 3. Run integration tests
cd /path/to/dmdevfs
./tests/run_integration_tests.sh /tmp/dmvfs/build/tests/fs_tester build/dmf/dmdevfs.dmf
```

#### Manual Testing with fs_tester

The fs_tester can test DMDEVFS in read-only mode:

```bash
# Clone dmvfs if you haven't already
git clone https://github.com/choco-technologies/dmvfs.git

# Build fs_tester
cd dmvfs
mkdir build && cd build
cmake .. -DDMVFS_BUILD_TESTS=ON
cmake --build .

# Run tests on dmdevfs module (read-only mode)
./tests/fs_tester --read-only-fs path/to/dmdevfs.dmf
```

## Test Coverage

Current automated tests verify:
- Module compilation succeeds
- Module output files are generated
- Build system integration works correctly

With fs_tester integration:
- File system interface implementation
- Read operations on device drivers
- Directory operations
- File metadata operations

Future test improvements could include:
- Device driver mock for testing file operations
- Write operation tests (if supported by drivers)
- Performance benchmarks

## Note on Test Limitations

DMDEVFS is a device driver-based filesystem that depends on:
1. Device driver modules (dmdrvi implementations)
2. Configuration files specifying device mappings
3. Actual hardware or mocked drivers

Full integration testing requires these dependencies to be available. The current test suite focuses on verifying the core module builds correctly. Device driver integration testing should be done with specific driver implementations.

## CI/CD Testing

The CI pipeline automatically:
1. Builds the dmdevfs module
2. Runs build verification tests
3. Verifies the module files are created

To add fs_tester to CI in the future, the workflow would need to:
1. Clone and build dmvfs
2. Run fs_tester against the built dmdevfs module
3. Report results

This can be added once device driver mocks or test drivers are available.
72 changes: 72 additions & 0 deletions tests/run_integration_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
# Script to run comprehensive tests on DMDEVFS module using fs_tester from dmvfs

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo "================================================"
echo " DMDEVFS Integration Test Runner"
echo "================================================"
echo ""

# Check if fs_tester path is provided
FS_TESTER_PATH="${1:-}"
DMDEVFS_MODULE="${2:-}"

if [ -z "$FS_TESTER_PATH" ] || [ -z "$DMDEVFS_MODULE" ]; then
echo "Usage: $0 <path_to_fs_tester> <path_to_dmdevfs.dmf>"
echo ""
echo "Example:"
echo " $0 /path/to/dmvfs/build/tests/fs_tester /path/to/dmdevfs/build/dmf/dmdevfs.dmf"
echo ""
echo "To build fs_tester:"
echo " git clone https://github.com/choco-technologies/dmvfs.git"
echo " cd dmvfs && mkdir build && cd build"
echo " cmake .. -DDMVFS_BUILD_TESTS=ON"
echo " cmake --build ."
exit 1
fi

# Check if files exist
if [ ! -f "$FS_TESTER_PATH" ]; then
echo -e "${RED}ERROR: fs_tester not found at: $FS_TESTER_PATH${NC}"
exit 1
fi

if [ ! -f "$DMDEVFS_MODULE" ]; then
echo -e "${RED}ERROR: dmdevfs module not found at: $DMDEVFS_MODULE${NC}"
exit 1
fi

echo -e "${GREEN}✓${NC} fs_tester found: $FS_TESTER_PATH"
echo -e "${GREEN}✓${NC} dmdevfs module found: $DMDEVFS_MODULE"
echo ""

# Make fs_tester executable
chmod +x "$FS_TESTER_PATH"

# Run tests in read-only mode
echo "Running fs_tester in read-only mode..."
echo "========================================"
echo ""

if "$FS_TESTER_PATH" --read-only-fs "$DMDEVFS_MODULE"; then
echo ""
echo -e "${GREEN}================================================${NC}"
echo -e "${GREEN} All tests PASSED!${NC}"
echo -e "${GREEN}================================================${NC}"
exit 0
else
echo ""
echo -e "${RED}================================================${NC}"
echo -e "${RED} Some tests FAILED${NC}"
echo -e "${RED}================================================${NC}"
exit 1
fi