Homework: PWM Controller (2026-03-16)#

Getting#

Exercise (Test Driven Development - TDD)#

  • New exercise: /exercises/pwm/_codebergaccountname_/

    • DO NOT MODIFY anything but pwm.{h,cpp}

    • Test driven development

    $ pwd
    /home/jfasch/My-Builds/FH-STECE2024-x86_64/exercises/pwm/_codebergaccountname_
    $ ./pwm-suite._codebergaccountname_
    Running main() from /home/jfasch/My-Projects/FH-STECE2024/googletest/googletest/src/gtest_main.cc
    [==========] Running 9 tests from 1 test suite.
    [----------] Global test environment set-up.
    [----------] 9 tests from pwm_test
    [ RUN      ] pwm_test.init_ok
    /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:52: Failure
    Value of: ok
      Actual: false
    Expected: true
    
    [  FAILED  ] pwm_test.init_ok (0 ms)
    [ RUN      ] pwm_test.init_nok
    [       OK ] pwm_test.init_nok (0 ms)
    [ RUN      ] pwm_test.set_period_ok
    /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:67: Failure
    Value of: ok
      Actual: false
    Expected: true
    
    [  FAILED  ] pwm_test.set_period_ok (0 ms)
    [ RUN      ] pwm_test.set_period__no_read_permissions_on_file
    /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:88: Failure
    Value of: ok
      Actual: false
    Expected: true
    
    [  FAILED  ] pwm_test.set_period__no_read_permissions_on_file (0 ms)
    [ RUN      ] pwm_test.get_period_ok
    /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:108: Failure
    Value of: ok
      Actual: false
    Expected: true
    
    [  FAILED  ] pwm_test.get_period_ok (0 ms)
    [ RUN      ] pwm_test.set_duty_cycle_ok
    /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:124: Failure
    Value of: ok
      Actual: false
    Expected: true
    
    [  FAILED  ] pwm_test.set_duty_cycle_ok (0 ms)
    [ RUN      ] pwm_test.get_duty_cycle_ok
    /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:137: Failure
    Value of: ok
      Actual: false
    Expected: true
    
    [  FAILED  ] pwm_test.get_duty_cycle_ok (0 ms)
    [ RUN      ] pwm_test.activate_deactivate_ok
    /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:153: Failure
    Value of: ok
      Actual: false
    Expected: true
    
    [  FAILED  ] pwm_test.activate_deactivate_ok (0 ms)
    [ RUN      ] pwm_test.is_active_ok
    /home/jfasch/My-Projects/FH-STECE2024/exercises/pwm/_codebergaccountname_/test_pwm.cpp:172: Failure
    Value of: ok
      Actual: false
    Expected: true
    
    [  FAILED  ] pwm_test.is_active_ok (0 ms)
    [----------] 9 tests from pwm_test (2 ms total)
    
    [----------] Global test environment tear-down
    [==========] 9 tests from 1 test suite ran. (2 ms total)
    [  PASSED  ] 1 test.
    [  FAILED  ] 8 tests, listed below:
    [  FAILED  ] pwm_test.init_ok
    [  FAILED  ] pwm_test.set_period_ok
    [  FAILED  ] pwm_test.set_period__no_read_permissions_on_file
    [  FAILED  ] pwm_test.get_period_ok
    [  FAILED  ] pwm_test.set_duty_cycle_ok
    [  FAILED  ] pwm_test.get_duty_cycle_ok
    [  FAILED  ] pwm_test.activate_deactivate_ok
    [  FAILED  ] pwm_test.is_active_ok
    
     8 FAILED TESTS
    
  • Running single tests and not all at once (handy for occasional strace debugging sessions)

    $ strace ./pwm-suite.jfasch --gtest_filter=pwm_test.set_period__no_read_permissions_on_file
    

Additional Information: PWM On Linux#

Additional Information: C++#

bool#

  • bool is a dedicated type, don’t have to misfit int

std::string#

std::filesystem::path#

  • PWM in sysfs uses paths heavily

  • std::filesystem::path

  • Conversion to C string: path.c_str(), just like std::string