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

Add a "TimeSource" class #1153

Merged
merged 5 commits into from
Jun 18, 2020
Merged

Conversation

andy31415
Copy link
Contributor

@andy31415 andy31415 commented Jun 17, 2020

Problem

System layer time source is a 'real' time source, making it hard to unit test time-dependent things. I would like to implement connection expiring logic, and controlling system time seems very useful in those instances.

Summary of Changes

Adds a templated 'time source' class which can be switched to either the test time source or keep using the system time.

This was my first idea, but it will start propagating templates around. if there are other suggestions to be able to control time for tests (maybe weak linkage or maybe our extern timesources could be swizzled at link time) please let me know. I find this should be clean enough, but if other methods are considered cleaner I would be interested to see them. This should have been a problem already in all other projects that handle time.

This is working towards #1088
fixes #1156 because I had qemu errors and I needed to see what failed.

@andy31415 andy31415 force-pushed the 01_add_time_source branch from 3884b35 to 391f2ef Compare June 17, 2020 16:04
@chip-bot
Copy link

Bloat report for job "Build Examples [ESP32]":

Bloat report for job 'Build Examples [ESP32]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/esp32-build/chip-wifi-echo.elf and example_binaries/esp32-build/chip-wifi-echo.elf:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[NEW]    +328  [ = ]       0    .xt.lit._ZN4chip15SecureTransportD5Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip15SecureTransportD0Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip15SecureTransportD2Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_15SecureTransportEEC2Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_15SecureTransportEED0Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_15SecureTransportEED2Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip9Transport4Base24SetMessageReceiveHandlerINS_15SecureTransportEEEvPFvRKNS_13MessageHeaderERKNS_4Inet12IPPacketInfoEPNS_6System12PacketBufferEPT_ESF_
[NEW]     +76  [ = ]       0    .xt.prop._ZN9__gnu_cxx5__ops12_Iter_negateIPFiiEEclIPKhEEbT_$isra$2
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_16SecureSessionMgrEEC2Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_16SecureSessionMgrEED0Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_16SecureSessionMgrEED2Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16SecureSessionMgrD0Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16SecureSessionMgrD2Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip9Transport4Base24SetMessageReceiveHandlerINS_16SecureSessionMgrEEEvPFvRKNS_13MessageHeaderERKNS_4Inet12IPPacketInfoEPNS_6System12PacketBufferEPT_ESF_
-0.1%     -81  [ = ]       0    .strtab
-0.0%     -84  [ = ]       0    .debug_loc
-0.0%     -96  -0.0%     -96    .flash.text
-0.0%    -102  [ = ]       0    .debug_str
-0.0%    -273  -0.0%     -64    [26 Others]
[DEL]    -328  [ = ]       0    .xt.lit._ZN4chip16SecureSessionMgrD5Ev
-0.0%    -476  [ = ]       0    .debug_info
-0.0% -1.01Ki  -0.0%    -160    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [nRF]":

Bloat report for job 'Build Examples [nRF]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/nrf-build/chip-nrf52840-lock-example.out and example_binaries/nrf-build/chip-nrf52840-lock-example.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[ = ]       0  [ = ]       0    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [main-build]":

Bloat report for job 'Build Examples [main-build]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/main-build/chip-standalone-demo.out and example_binaries/main-build/chip-standalone-demo.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
+4.3%    +142  [ = ]       0    [Unmapped]
-0.3%      -8  -0.3%      -8    .eh_frame_hdr
-0.3%     -16  [ = ]       0    .debug_aranges
-0.0%     -16  [ = ]       0    .debug_macro
-0.1%     -16  [ = ]       0    .debug_ranges
-0.2%     -24  [ = ]       0    .symtab
-0.0%     -36  [ = ]       0    .debug_line
-0.3%     -40  -0.3%     -40    .eh_frame
-0.4%     -79  [ = ]       0    .strtab
-0.3%     -96  -0.3%     -96    .text
-0.0%    -201  [ = ]       0    .debug_str
-0.4%    -336  [ = ]       0    .debug_loc
-0.2%    -674  [ = ]       0    .debug_info
-0.1% -1.37Ki  -0.0%    -144    TOTAL


Copy link
Contributor

@gerickson gerickson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andy31415, please sync up with @robszewczyk who has been in the process of open sourcing Nest's "Plaid" time manipulation framework for some time that will address this issue without propagating templates around.

@andy31415
Copy link
Contributor Author

@andy31415, please sync up with @robszewczyk who has been in the process of open sourcing Nest's "Plaid" time manipulation framework for some time that will address this issue without propagating templates around.

Messaged Rob offline. One worry I would have is that seems to include both open source (seems time or laywer sensitive maybe ... moving from closed to open sometimes is involved) and inclusion into CHIP and that may be a long timeline.

If this takes longer than a few days (which i find very likely) I would prefer to unblock transport layer and session management by including the template approach. I volunteer to switch to Plaid after that as soon as it lands as a first priority.

@gerickson
Copy link
Contributor

@andy31415, please sync up with @robszewczyk who has been in the process of open sourcing Nest's "Plaid" time manipulation framework for some time that will address this issue without propagating templates around.

Messaged Rob offline. One worry I would have is that seems to include both open source (seems time or laywer sensitive maybe ... moving from closed to open sometimes is involved) and inclusion into CHIP and that may be a long timeline.

If this takes longer than a few days (which i find very likely) I would prefer to unblock transport layer and session management by including the template approach. I volunteer to switch to Plaid after that as soon as it lands as a first priority.

It's already been fundamentally approved. Maybe you can help @robszewczyk make it happen. It's the right path here; let's make it happen.

@chip-bot
Copy link

Bloat report for job "Build Examples [nRF]":

Bloat report for job 'Build Examples [nRF]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/nrf-build/chip-nrf52840-lock-example.out and example_binaries/nrf-build/chip-nrf52840-lock-example.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[ = ]       0  [ = ]       0    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [ESP32]":

Bloat report for job 'Build Examples [ESP32]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/esp32-build/chip-wifi-echo.elf and example_binaries/esp32-build/chip-wifi-echo.elf:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[NEW]    +328  [ = ]       0    .xt.lit._ZN4chip15SecureTransportD5Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip15SecureTransportD0Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip15SecureTransportD2Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_15SecureTransportEEC2Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_15SecureTransportEED0Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_15SecureTransportEED2Ev
[NEW]     +76  [ = ]       0    .xt.prop._ZN4chip9Transport4Base24SetMessageReceiveHandlerINS_15SecureTransportEEEvPFvRKNS_13MessageHeaderERKNS_4Inet12IPPacketInfoEPNS_6System12PacketBufferEPT_ESF_
[NEW]     +76  [ = ]       0    .xt.prop._ZN9__gnu_cxx5__ops12_Iter_negateIPFiiEEclIPKhEEbT_$isra$2
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_16SecureSessionMgrEEC2Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_16SecureSessionMgrEED0Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16ReferenceCountedINS_16SecureSessionMgrEED2Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16SecureSessionMgrD0Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip16SecureSessionMgrD2Ev
[DEL]     -76  [ = ]       0    .xt.prop._ZN4chip9Transport4Base24SetMessageReceiveHandlerINS_16SecureSessionMgrEEEvPFvRKNS_13MessageHeaderERKNS_4Inet12IPPacketInfoEPNS_6System12PacketBufferEPT_ESF_
-0.1%     -81  [ = ]       0    .strtab
-0.0%     -84  [ = ]       0    .debug_loc
-0.0%     -96  -0.0%     -96    .flash.text
-0.0%    -102  [ = ]       0    .debug_str
-0.0%    -273  -0.0%     -56    [24 Others]
[DEL]    -328  [ = ]       0    .xt.lit._ZN4chip16SecureSessionMgrD5Ev
-0.0%    -476  [ = ]       0    .debug_info
-0.0% -1.01Ki  -0.0%    -152    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [main-build]":

Bloat report for job 'Build Examples [main-build]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/main-build/chip-standalone-demo.out and example_binaries/main-build/chip-standalone-demo.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
+4.3%    +142  [ = ]       0    [Unmapped]
-0.3%      -8  -0.3%      -8    .eh_frame_hdr
-0.3%     -16  [ = ]       0    .debug_aranges
-0.0%     -16  [ = ]       0    .debug_macro
-0.1%     -16  [ = ]       0    .debug_ranges
-0.2%     -24  [ = ]       0    .symtab
-0.0%     -36  [ = ]       0    .debug_line
-0.3%     -40  -0.3%     -40    .eh_frame
-0.4%     -79  [ = ]       0    .strtab
-0.3%     -96  -0.3%     -96    .text
-0.0%    -201  [ = ]       0    .debug_str
-0.4%    -336  [ = ]       0    .debug_loc
-0.2%    -674  [ = ]       0    .debug_info
-0.1% -1.37Ki  -0.0%    -144    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [nRF]":

Bloat report for job 'Build Examples [nRF]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/nrf-build/chip-nrf52840-lock-example.out and example_binaries/nrf-build/chip-nrf52840-lock-example.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[ = ]       0  [ = ]       0    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [ESP32]":

Bloat report for job 'Build Examples [ESP32]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/esp32-build/chip-wifi-echo.elf and example_binaries/esp32-build/chip-wifi-echo.elf:

  FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%      +8  +0.0%      +8    .flash.rodata
-0.1%      -8  [ = ]       0    [Unmapped]
[ = ]       0  +0.0%      +8    TOTAL


@andy31415
Copy link
Contributor Author

@andy31415, please sync up with @robszewczyk who has been in the process of open sourcing Nest's "Plaid" time manipulation framework for some time that will address this issue without propagating templates around.

Messaged Rob offline. One worry I would have is that seems to include both open source (seems time or laywer sensitive maybe ... moving from closed to open sometimes is involved) and inclusion into CHIP and that may be a long timeline.
If this takes longer than a few days (which i find very likely) I would prefer to unblock transport layer and session management by including the template approach. I volunteer to switch to Plaid after that as soon as it lands as a first priority.

It's already been fundamentally approved. Maybe you can help @robszewczyk make it happen. It's the right path here; let's make it happen.

Result of talking with Rob seems to be: Plaid is really suitable to integration and functional test, but has high overhead for unit tests (it requires and uses a network syncrhonization server).

This PR proposes infrastructure suitable for unit tests (but not for integration tests as there is no sync), so I would still like to be considered. @gerickson what are your thoghts?

@chip-bot
Copy link

Bloat report for job "Build Examples [main-build]":

Bloat report for job 'Build Examples [main-build]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/main-build/chip-standalone-demo.out and example_binaries/main-build/chip-standalone-demo.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[ = ]       0  [ = ]       0    TOTAL


public:
uint64_t GetCurrentMonotonicTimeMs() { return mCurrentTimeMs; }

void SetCurrentMonotonicTimeMs(uint64_t value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be a companion Set... for the kSystem that's a no-op?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of that, however it does not seem like the platform layer has a usable set time and I did not want to deceive users.

I could have a CHIP_ERROR return that returns error on system and success on test ... but then I wonder why bother if compiler can already catch correct vs incorrect usages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LMK if you think a CHIP_ERROR Set* method would be useful in all instances and I can add it. As it stands, I am leaning towards compile time error rather than runtime, but I agree that this may confuse some compilers (I was surprised it built myself .... but hey, I;ll take it)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally for "fly what you test and test what you fly", so this seems a bit akimbo to that to begin with; however, I think, in this case, a compile-time error is probably better than a run-time error.

@chip-bot
Copy link

Bloat report for job "Build Examples [ESP32]":

Bloat report for job 'Build Examples [ESP32]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/esp32-build/chip-wifi-echo.elf and example_binaries/esp32-build/chip-wifi-echo.elf:

  FILE SIZE        VM SIZE    
--------------  -------------- 
+0.1% +1.91Ki  [ = ]       0    .debug_info
+0.3% +1.10Ki  [ = ]       0    .debug_str
+0.0%    +540  [ = ]       0    .debug_line
+0.1%    +420  [ = ]       0    .debug_loc
+1.6%    +285  [ = ]       0    .shstrtab
[NEW]    +232  [ = ]       0    .xt.prop._ZSt9__find_ifIPKhN9__gnu_cxx5__ops12_Iter_negateIPFiiEEEET_S8_S8_T0_St26random_access_iterator_tag
+0.0%    +196  +0.0%    +196    .flash.text
+0.1%    +159  [ = ]       0    .strtab
+0.0%    +143  [ = ]       0    .debug_abbrev
+0.1%     +80  [ = ]       0    .symtab
[NEW]     +76  [ = ]       0    .xt.prop._ZN9__gnu_cxx5__ops12_Iter_negateIPFiiEEclIPKhEEbT_$isra$3
+0.0%     +48  [ = ]       0    .debug_frame
+0.1%     +40  [ = ]       0    .debug_ranges
 +40%     +40  [ = ]       0    .xt.prop._ZNK4chip8OptionalIyE5ValueEv
+0.0%     +16  [ = ]       0    .debug_aranges
+0.1%      +8  +0.1%      +8    .dram0.data
-0.0%      -4  [ = ]       0    [Unmapped]
+0.1% +5.23Ki  +0.0%    +204    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [nRF]":

Bloat report for job 'Build Examples [nRF]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/nrf-build/chip-nrf52840-lock-example.out and example_binaries/nrf-build/chip-nrf52840-lock-example.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[ = ]       0  [ = ]       0    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [main-build]":

Bloat report for job 'Build Examples [main-build]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/main-build/chip-standalone-demo.out and example_binaries/main-build/chip-standalone-demo.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%    +121  [ = ]       0    .debug_info
+0.1%     +26  [ = ]       0    .debug_abbrev
+0.2%      +8  [ = ]       0    [Unmapped]
-0.0%      -4  [ = ]       0    .debug_loc
-0.1%      -8  -0.1%      -8    .eh_frame
-0.0%     -31  [ = ]       0    .debug_line
-1.2%    -144  [ = ]       0    .debug_ranges
-0.0%     -32  -0.0%      -8    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [nRF]":

Bloat report for job 'Build Examples [nRF]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/nrf-build/chip-nrf52840-lock-example.out and example_binaries/nrf-build/chip-nrf52840-lock-example.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[ = ]       0  [ = ]       0    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [ESP32]":

Bloat report for job 'Build Examples [ESP32]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/esp32-build/chip-wifi-echo.elf and example_binaries/esp32-build/chip-wifi-echo.elf:

  FILE SIZE        VM SIZE    
--------------  -------------- 
+0.2%     +16  [ = ]       0    [Unmapped]
-0.1%      -8  -0.1%      -8    .dram0.data
-0.0%      -8  -0.0%      -8    .flash.rodata
[ = ]       0  -0.0%     -16    TOTAL


@chip-bot
Copy link

Bloat report for job "Build Examples [main-build]":

Bloat report for job 'Build Examples [main-build]'

Files found only in the baseline:
  bloat_report.txt

Bloat difference between master_binaries/main-build/chip-standalone-demo.out and example_binaries/main-build/chip-standalone-demo.out:

  FILE SIZE        VM SIZE    
--------------  -------------- 
[ = ]       0  [ = ]       0    TOTAL


Copy link
Contributor

@woody-apple woody-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@woody-apple woody-apple self-requested a review June 18, 2020 14:50
Copy link
Contributor

@woody-apple woody-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/pullapprove-test

version: 3

groups:
    ############################################################
    #  Base Required Reviewers
    ############################################################
    required-reviewers:
        type: required
        conditions:
            - len(groups.approved.include('reviewer-groups-*')) >= 3
        reviews:
            required: 3

    ############################################################
    #  Reviewer Groups
    ############################################################
    reviewer-groups-amazon:
        type: optional
        conditions:
            - files.include('*')
        reviewers:
            teams:
                - reviewers-amazon
    reviewer-groups-apple:
        type: optional
        conditions:
            - files.include('*')
        reviewers:
            teams:
                - reviewers-apple
    reviewer-groups-comcast:
        type: optional
        conditions:
            - files.include('*')
        reviewers:
            teams:
                - reviewers-comcast
    reviewer-groups-google:
        type: optional
        conditions:
            - files.include('*')
        reviewers:
            teams:
                - reviewers-google
    reviewers-samsung:
        type: optional
        conditions:
            - files.include('*')
        reviewers:
            teams:
                - reviewers-samsung

@pullapprove
Copy link

pullapprove bot commented Jun 18, 2020

@andy31415
Copy link
Contributor Author

@saurabhst @jelderton ?

@andy31415
Copy link
Contributor Author

@jelderton ?

It seems that now with the pullapprove, I still get issues even though grant already approved. Does this make it harder for folks with key access to submit since their own ownership does not carry over?

@woody-apple can we somehow update things for this odd situation? I cannot self-approve I think.

@andy31415 andy31415 merged commit b3cffd6 into project-chip:master Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESP32-QEMU unit tests do not export test artifacts
7 participants