Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Restore basic unit tests #271

Merged
merged 1 commit into from
Jan 23, 2025
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
12 changes: 9 additions & 3 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# .arduino-ci.yml

# Compilation settings
compile:
platforms:
- uno
libraries:
- "OneWire"
skip_unittest: true

aux_libraries_for_ci:
- "OneWire"
# Unit testing settings
unittest:
platforms:
- uno
libraries:
- "OneWire"
6 changes: 6 additions & 0 deletions .arduino_ci/.arduino-ci.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define ARDUINO_CI 1

// Mock OneWire GPIO functions
uint8_t digitalPinToBitMask(uint8_t pin) { return 1 << (pin % 8); }
void* digitalPinToPort(uint8_t pin) { static uint8_t dummy; return &dummy; }
void* portModeRegister(void* port) { return port; }
25 changes: 25 additions & 0 deletions .arduino_ci/util/crc16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef CRC16_H
#define CRC16_H

#ifdef __cplusplus
extern "C" {
#endif

// Pure C implementation to replace the ASM version
static inline uint16_t _crc16_update(uint16_t crc, uint8_t data) {
unsigned int i;
crc ^= data;
for (i = 0; i < 8; ++i) {
if (crc & 1)
crc = (crc >> 1) ^ 0xA001;
else
crc = (crc >> 1);
}
return crc;
}

#ifdef __cplusplus
}
#endif

#endif
82 changes: 82 additions & 0 deletions .github/workflows/arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Arduino-Temperature-Control-Library Github Workflow

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install AVR dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcc-avr avr-libc

- name: Create required directories
run: |
mkdir -p $GITHUB_WORKSPACE/libraries
mkdir -p $GITHUB_WORKSPACE/.arduino15
mkdir -p $GITHUB_WORKSPACE/Arduino

- name: Setup Arduino CLI
uses: arduino/setup-arduino-cli@v1

- name: Configure Arduino CLI and install cores
run: |
arduino-cli config init
arduino-cli config set library.enable_unsafe_install true
arduino-cli config add board_manager.additional_urls https://arduino.esp8266.com/stable/package_esp8266com_index.json
arduino-cli core update-index
arduino-cli core install arduino:avr
arduino-cli core install esp8266:esp8266

- name: Install OneWire library
run: |
arduino-cli lib install OneWire
# Replace the CRC implementation directly in the OneWire library
cat > /home/runner/Arduino/libraries/OneWire/util/crc16.h << 'EOF'
#ifndef CRC16_H
#define CRC16_H
#include <stdint.h>

static inline uint16_t _crc16_update(uint16_t crc, uint8_t a)
{
crc ^= a;
for (uint8_t i = 0; i < 8; ++i) {
if (crc & 1)
crc = (crc >> 1) ^ 0xA001;
else
crc = (crc >> 1);
}
return crc;
}

#endif
EOF

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2.0'

- name: Install bundler
run: |
gem install bundler

- name: Install dependencies
run: |
bundle install

- name: List repository contents (for debugging)
run: |
ls -R

- name: Remove Blacklisted Example Sketches
run: |
echo "Removing blacklisted example sketches..."
rm -f examples/ESP-WebServer/ESP-WebServer.ino

- name: Run tests
run: |
bundle exec arduino_ci.rb
39 changes: 0 additions & 39 deletions .github/workflows/arduino_test_runner.yml

This file was deleted.

3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "arduino_ci", "~> 1.6.2"
20 changes: 20 additions & 0 deletions test/TestDallasTemperature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <DallasTemperature.h>
#include <ArduinoUnitTests.h>

unittest(test_initialization) {
OneWire oneWire(2); // Simulate OneWire on pin 2
DallasTemperature sensors(&oneWire);

sensors.begin();
assertEqual(0, sensors.getDeviceCount());
}

unittest(test_parasite_power_mode) {
OneWire oneWire(2);
DallasTemperature sensors(&oneWire);

sensors.begin();
assertFalse(sensors.isParasitePowerMode());
}

unittest_main()
22 changes: 0 additions & 22 deletions test/TestDallasTemperature.cpp.disabled

This file was deleted.

8 changes: 0 additions & 8 deletions test/basic_test.cpp

This file was deleted.

Loading