diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4e29ed9af..9863dcd46 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,4 +2,4 @@ # the repo. Unless a later match takes precedence, # @global-owner1 and @global-owner2 will be requested for # review when someone opens a pull request. -* @rdkcentral/rdke_ghec_tr69_maintainer @rdkcentral/rdke_ghec_tr69_admin +* @rdkcentral/tr69hostif-maintainers diff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml new file mode 100644 index 000000000..c58b1b0b1 --- /dev/null +++ b/.github/workflows/cla.yml @@ -0,0 +1,20 @@ +name: "CLA" + +permissions: + contents: read + pull-requests: write + actions: write + statuses: write + +on: + issue_comment: + types: [created] + pull_request_target: + types: [opened, closed, synchronize] + +jobs: + CLA-Lite: + name: "Signature" + uses: rdkcentral/cmf-actions/.github/workflows/cla.yml@v1 + secrets: + PERSONAL_ACCESS_TOKEN: ${{ secrets.CLA_ASSISTANT }} diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 000000000..2e29b0b79 --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,52 @@ +name: Code Coverage + +on: + pull_request: + branches: [ main ] + +jobs: + execute-unit-code-coverage-report-on-release: + name: Test coverage report for release + runs-on: ubuntu-latest + container: + image: ghcr.io/rdkcentral/docker-rdk-ci:latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run unit tests with coverage flags enabled + run: | + sh run_ut.sh --enable-cov + - name: Caculate the code coverage summary + run: | + lcov --list tr69hostif_coverage.info | grep "Lines\|Total" > /tmp/coverage_summary.txt + cd - + + - name: Update the coverage report to Pull request using actions + uses: actions/github-script@v4 + with: + script: | + const fs = require('fs'); + const lcov_result = fs.readFileSync('/tmp/coverage_summary.txt', 'utf8'); + + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: + '## Code Coverage Summary \n' + + ' ' + + '```' + + lcov_result + + '```' + }); + - name: Generate the html report + run: | + genhtml tr69hostif_coverage.info --output-directory /tmp/coverage_report + cd - + - name: Upload the coverage report to Pull request using actions + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: /tmp/coverage_report diff --git a/.github/workflows/fossid_integration_stateless_diffscan_target_repo.yml b/.github/workflows/fossid_integration_stateless_diffscan_target_repo.yml index da02b8b4f..7b8c1cba1 100644 --- a/.github/workflows/fossid_integration_stateless_diffscan_target_repo.yml +++ b/.github/workflows/fossid_integration_stateless_diffscan_target_repo.yml @@ -1,11 +1,18 @@ name: Fossid Stateless Diff Scan -on: pull_request +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + contents: read + pull-requests: read jobs: call-fossid-workflow: - uses: rdkcentral/build_tools_workflows/.github/workflows/fossid_integration_stateless_diffscan.yml@develop - secrets: + if: ${{ ! github.event.pull_request.head.repo.fork }} + uses: rdkcentral/build_tools_workflows/.github/workflows/fossid_integration_stateless_diffscan.yml@1.0.0 + secrets: FOSSID_CONTAINER_USERNAME: ${{ secrets.FOSSID_CONTAINER_USERNAME }} FOSSID_CONTAINER_PASSWORD: ${{ secrets.FOSSID_CONTAINER_PASSWORD }} FOSSID_HOST_USERNAME: ${{ secrets.FOSSID_HOST_USERNAME }} diff --git a/CHANGELOG.md b/CHANGELOG.md index abdab8f40..9872a17ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,74 +4,341 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -#### [1.0.12](https://github.com-venkat0557/rdkcentral/tr69hostif/compare/1.0.11...1.0.12) +#### [1.3.0](https://github.com/rdkcentral/tr69hostif/compare/1.2.9...1.3.0) -- RDKEMW-2308: Secure wrapper API fixes [`#53`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/53) -- Rebase with develop [`#55`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/55) -- RDKEMW-1803: Add debugs for Mutex issue [`#54`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/54) -- Fix libsyswrapper to run in background [`033ce3c`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/033ce3c77f38e3c0b8b80b98b9a8184d942ca0ba) -- Fix libsyswrapper calls [`969dc69`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/969dc69d2bd1ad05f8597b009c91846cee3d7ea1) -- Update Device_IP_Interface_IPv4Address.cpp [`c53c0b8`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/c53c0b8c1b7fb05b9d1d21b7fa1d91222933dcdb) +- RDKEMW-8175:Segmented global/system-wide profile for rdke [`#316`](https://github.com/rdkcentral/tr69hostif/pull/316) +- RDK-60387-[tr69hostif] Reduce repetitive logging [`#334`](https://github.com/rdkcentral/tr69hostif/pull/334) +- RDKEMW-10786: Add new parameter for screencapture api [`#329`](https://github.com/rdkcentral/tr69hostif/pull/329) +- Merge tag '1.2.9' into develop [`3fbb483`](https://github.com/rdkcentral/tr69hostif/commit/3fbb483212448f1b10d3539eca96188930d4bc0f) -#### [1.0.11](https://github.com-venkat0557/rdkcentral/tr69hostif/compare/1.0.10...1.0.11) +#### [1.2.9](https://github.com/rdkcentral/tr69hostif/compare/1.2.8...1.2.9) + +> 5 December 2025 + +- RDK-59250-RDKE-tr69hostif-100% L2 coverage [`#319`](https://github.com/rdkcentral/tr69hostif/pull/319) +- RDKEMW-10639: Convert memcapture tool as RDM downloadable package [`#320`](https://github.com/rdkcentral/tr69hostif/pull/320) +- RDKTV-39100 : [SECVULN] migrate configuration files from /opt to /opt/secure [`#318`](https://github.com/rdkcentral/tr69hostif/pull/318) +- RDKEMW-6128: Update hostIf_IARM_ReqHandler.cpp [`#312`](https://github.com/rdkcentral/tr69hostif/pull/312) +- Fixing the bug for ethernet interface [`#309`](https://github.com/rdkcentral/tr69hostif/pull/309) +- 1.2.9 release changelog updates [`79e3a45`](https://github.com/rdkcentral/tr69hostif/commit/79e3a45f1b02b45bb50154f50f29ae5c2550141c) +- Merge tag '1.2.8' into develop [`77b380c`](https://github.com/rdkcentral/tr69hostif/commit/77b380c1c7e64e5326e3357bbe6b9a35d7d51189) + +#### [1.2.8](https://github.com/rdkcentral/tr69hostif/compare/1.2.7...1.2.8) + +> 30 October 2025 + +- RDKEMW-9754: DAC bundle config parameter as RFC [`#304`](https://github.com/rdkcentral/tr69hostif/pull/304) +- ES1-2915-[ES1]: xPKI cert creation is failed due to unable to retrieve tr181 parameters [`#303`](https://github.com/rdkcentral/tr69hostif/pull/303) +- RDK-59202-[RDK-V/E] Data Model Federation For tr69hostif [`#295`](https://github.com/rdkcentral/tr69hostif/pull/295) +- 1.2.8 release changelog updates [`0717da2`](https://github.com/rdkcentral/tr69hostif/commit/0717da2a067cd28a9a13a6112599f30e5f40557f) +- Merge tag '1.2.7' into develop [`37a3e76`](https://github.com/rdkcentral/tr69hostif/commit/37a3e7649a2d01b2edcf805006ff562a2aa5aeea) + +#### [1.2.7](https://github.com/rdkcentral/tr69hostif/compare/1.2.6...1.2.7) + +> 13 October 2025 + +- RDK-59587 : RFC feature to support Downloadable IUI Fallback [`#291`](https://github.com/rdkcentral/tr69hostif/pull/291) +- RDKE-900 RDKEMW-4899: Default to MTLS connection on all endpoints [`#270`](https://github.com/rdkcentral/tr69hostif/pull/270) +- Rebase with develop [`#290`](https://github.com/rdkcentral/tr69hostif/pull/290) +- Update CODEOWNERS [`#289`](https://github.com/rdkcentral/tr69hostif/pull/289) +- RDKEMW-8971: fix retry logic [`#288`](https://github.com/rdkcentral/tr69hostif/pull/288) +- Rebase with develop [`#274`](https://github.com/rdkcentral/tr69hostif/pull/274) +- Rebase with develop [`#272`](https://github.com/rdkcentral/tr69hostif/pull/272) +- 1.2.7 release changelog updates [`107fae2`](https://github.com/rdkcentral/tr69hostif/commit/107fae207def673e965d97899c82fe71b70f510f) +- Merge tag '1.2.6' into develop [`2e546d5`](https://github.com/rdkcentral/tr69hostif/commit/2e546d5de878a5c8ee7a3558099cdcddc28f10a4) + +#### [1.2.6](https://github.com/rdkcentral/tr69hostif/compare/1.2.5...1.2.6) + +> 7 October 2025 + +- RDKEMW-7921:Enable network isolation to deny SSH from Dev Jump VM to Prod VM using SHORTS [`#278`](https://github.com/rdkcentral/tr69hostif/pull/278) +- RDK-41133 : New RFC to force maintenance every X mins [`#281`](https://github.com/rdkcentral/tr69hostif/pull/281) +- Build error due to L1 changes [`#279`](https://github.com/rdkcentral/tr69hostif/pull/279) +- RDK-58220 : [RDKE] Migrate Functionality In TR-69Hostif And NTP Scripts To Core Modules [`#276`](https://github.com/rdkcentral/tr69hostif/pull/276) +- RDKEMW-6455: separate Blacklist RFC, and enabled by default [`#273`](https://github.com/rdkcentral/tr69hostif/pull/273) +- Deploy fossid_integration_stateless_diffscan_target_repo action [`#271`](https://github.com/rdkcentral/tr69hostif/pull/271) +- RDK-58962 [ tr69hostif ] : L1 Functional Coverage from 56% to 75-80% [`#252`](https://github.com/rdkcentral/tr69hostif/pull/252) +- Deploy cla action [`#186`](https://github.com/rdkcentral/tr69hostif/pull/186) +- SERXIONE-7905: Device is not accessible via SSH after DRI execution [`#267`](https://github.com/rdkcentral/tr69hostif/pull/267) +- 1.2.6 release changelog updates [`382af71`](https://github.com/rdkcentral/tr69hostif/commit/382af7197b338cc4ec379d14fa742f160a66caca) +- Potential fix for code scanning alert no. 10: Too few arguments to formatting function [`9e00c40`](https://github.com/rdkcentral/tr69hostif/commit/9e00c401c8a3901d0c22efaf5b06c34ecfa438ba) +- Merge tag '1.2.5' into develop [`4be75e7`](https://github.com/rdkcentral/tr69hostif/commit/4be75e7d29ebdd31980a202d103a63d8d941d5d6) + +#### [1.2.5](https://github.com/rdkcentral/tr69hostif/compare/1.2.4...1.2.5) + +> 24 September 2025 + +- RDK-58963-[RDK-V/E] Federated Source Code For tr69hostif - Phase 2 [`#250`](https://github.com/rdkcentral/tr69hostif/pull/250) +- RDKEMW-8367: Add Valid Public NTP servers for community [`#255`](https://github.com/rdkcentral/tr69hostif/pull/255) +- DELIA-68569 - WebPA Query fails for RRD Enabled command [`#235`](https://github.com/rdkcentral/tr69hostif/pull/235) +- rebase [`#244`](https://github.com/rdkcentral/tr69hostif/pull/244) +- RDK-57737 [ tr69hostif ] : L1 Functional Coverage from 31.2% to 75-80% [`#225`](https://github.com/rdkcentral/tr69hostif/pull/225) +- Rebase [`#237`](https://github.com/rdkcentral/tr69hostif/pull/237) +- Rebase [`#234`](https://github.com/rdkcentral/tr69hostif/pull/234) +- rebase [`#231`](https://github.com/rdkcentral/tr69hostif/pull/231) +- 1.2.5 release changelog updates [`a787aa4`](https://github.com/rdkcentral/tr69hostif/commit/a787aa4866e769fad654d2ee89f16afa21204ede) +- Update webpa_parameter.cpp [`7b12e1f`](https://github.com/rdkcentral/tr69hostif/commit/7b12e1f3b1790899806f41f1144c17435905d450) +- Merge tag '1.2.4' into develop [`364c312`](https://github.com/rdkcentral/tr69hostif/commit/364c312c2c7cc15d94350692024cb5142336e3e6) + +#### [1.2.4](https://github.com/rdkcentral/tr69hostif/compare/1.2.3...1.2.4) + +> 27 August 2025 + +- RDKEMW-4759 - Review and Analyze the RRD Static Profiles for RDK devices [`#198`](https://github.com/rdkcentral/tr69hostif/pull/198) +- RDKEMW-7135 : Gamepad RFC is not enabled by default [`#228`](https://github.com/rdkcentral/tr69hostif/pull/228) +- RDKTV-38130-[RDKE_Trials][8.2p2s2]: Increase in "tr69hostif" crash with function "hostIf_WiFi_SSID::get_Device_WiFi_SSID_Fields" and "81598460" fingerprint [`#223`](https://github.com/rdkcentral/tr69hostif/pull/223) +- Fix tr69hostif native build failure [`#232`](https://github.com/rdkcentral/tr69hostif/pull/232) +- Rebase [`#209`](https://github.com/rdkcentral/tr69hostif/pull/209) +- 1.2.4 release changelog updates [`b112be6`](https://github.com/rdkcentral/tr69hostif/commit/b112be6f22ab852b37604562d3a4341d94160cdb) +- Merge tag '1.2.3' into develop [`84c45dd`](https://github.com/rdkcentral/tr69hostif/commit/84c45dd1c8bac75d25f06fbbc14575c02d8a153a) +- Update Device_DeviceInfo.cpp [`5441b70`](https://github.com/rdkcentral/tr69hostif/commit/5441b702ad40eb9523499670b9254ea3fcbda0cc) + +#### [1.2.3](https://github.com/rdkcentral/tr69hostif/compare/1.2.2...1.2.3) + +> 21 August 2025 + +- RDK-56291 - [RDKE] Increase L2 Test Coverage For Remote Debugger : Target 80% [ Phase 2 ] [`#227`](https://github.com/rdkcentral/tr69hostif/pull/227) +- [RDKEMW-5582] -[RDKE] tr69hostif.log contains any garbage data for the paramValue field [`#219`](https://github.com/rdkcentral/tr69hostif/pull/219) +- RDKEMW-6520: tr69hostif service starts before iarmbusd [`#218`](https://github.com/rdkcentral/tr69hostif/pull/218) +- RDKEMW-4344 : Include the missed RFCs in RDKE. [`#216`](https://github.com/rdkcentral/tr69hostif/pull/216) +- Update hostIf_msgHandler.cpp [`05c52c6`](https://github.com/rdkcentral/tr69hostif/commit/05c52c6c5bb363bb3f56eb62e20f766efb795bfb) +- Update hostIf_msgHandler.cpp [`61a1355`](https://github.com/rdkcentral/tr69hostif/commit/61a1355641b0ca47ae0d24b65f6a66b80210a9d5) +- Update hostIf_msgHandler.cpp [`b273a3a`](https://github.com/rdkcentral/tr69hostif/commit/b273a3a8f9cb9a3d570fcbc20a09b7ca97c88daf) + +#### [1.2.2](https://github.com/rdkcentral/tr69hostif/compare/1.2.1...1.2.2) + +> 29 July 2025 + +- RDKEMW-6193 Code Coverage support for tr69hostif [`#211`](https://github.com/rdkcentral/tr69hostif/pull/211) +- RDKEMW-6328: set AVHijack rfc to false [`#208`](https://github.com/rdkcentral/tr69hostif/pull/208) +- RDK-58323: Canary firmware updates [`#199`](https://github.com/rdkcentral/tr69hostif/pull/199) +- Changelog updates for release 1.2.2 [`d3eda52`](https://github.com/rdkcentral/tr69hostif/commit/d3eda5205f0cb00c7ab8bbcccb70a31a7ce29a45) +- Merge tag '1.2.1' into develop [`17d019b`](https://github.com/rdkcentral/tr69hostif/commit/17d019b0bed5e8cc9c1f4fe68520c08fc530ff00) + +#### [1.2.1](https://github.com/rdkcentral/tr69hostif/compare/1.2.0...1.2.1) + +> 18 July 2025 + +- RDK-58526 : Default IPControl RFC for EU partners [`#203`](https://github.com/rdkcentral/tr69hostif/pull/203) +- RDK-57868 : Default IPControl RFC for EU partners [`#200`](https://github.com/rdkcentral/tr69hostif/pull/200) +- RDK-57867 : Default the IUI layer separation RFC globally for EntOS [`#193`](https://github.com/rdkcentral/tr69hostif/pull/193) +- 1.2.1 release changelog updates [`fe9e71f`](https://github.com/rdkcentral/tr69hostif/commit/fe9e71f712ffef234215145461d767ae7d1691a4) +- Merge tag '1.2.0' into develop [`9b98df0`](https://github.com/rdkcentral/tr69hostif/commit/9b98df0330008138a47b6f18a4314df6f0a7adc1) + +#### [1.2.0](https://github.com/rdkcentral/tr69hostif/compare/1.1.9...1.2.0) + +> 27 June 2025 + +- RDK-57649 [RDKE] - TR69HostIf Performance Monitoring and Optimized Logging [`#185`](https://github.com/rdkcentral/tr69hostif/pull/185) +- 1.2.0 release changelog updates [`0e68c7e`](https://github.com/rdkcentral/tr69hostif/commit/0e68c7e79ca5b155a93fa1ac6a11db218486504d) +- Merge tag '1.1.9' into develop [`083a042`](https://github.com/rdkcentral/tr69hostif/commit/083a042ce2eb4bcfc24bf95f24e8f04e897fe7c4) + +#### [1.1.9](https://github.com/rdkcentral/tr69hostif/compare/1.1.8...1.1.9) + +> 18 June 2025 + +- RDKTV-36715: Logs flooding issue observed in tr69hostif.log [`#181`](https://github.com/rdkcentral/tr69hostif/pull/181) +- 1.1.9 release changelog updates [`4e8c53e`](https://github.com/rdkcentral/tr69hostif/commit/4e8c53e7592386bd584e4b528e207b5931aa880b) +- Update hostIf_IPClient_ReqHandler.cpp [`1e6bff6`](https://github.com/rdkcentral/tr69hostif/commit/1e6bff6c3773dbf6665a68ed952f687553fe6cef) +- Merge tag '1.1.8' into develop [`39c4fc6`](https://github.com/rdkcentral/tr69hostif/commit/39c4fc61311cad2a685cb7ac15e9321fdbddc6fe) + +#### [1.1.8](https://github.com/rdkcentral/tr69hostif/compare/1.1.7...1.1.8) + +> 17 June 2025 + +- RDKEMW-4029 Hard stop for tr69hostif service during cleanup [`#175`](https://github.com/rdkcentral/tr69hostif/pull/175) +- RDKTV-36715: Logs flooding issue observed in tr69hostif.log "refreshInterfaceName:" [`#176`](https://github.com/rdkcentral/tr69hostif/pull/176) +- RDK-49251 [RDK-E] L2 Test In CI Loops For Firewall [`#170`](https://github.com/rdkcentral/tr69hostif/pull/170) +- RDKTV-36715: Logs flooding issue observed in tr69hostif.log "refreshInterfaceName:" [`#169`](https://github.com/rdkcentral/tr69hostif/pull/169) +- RDKEMW-3396:Default AV Hijack RFC to true [`#174`](https://github.com/rdkcentral/tr69hostif/pull/174) +- Rdkemw 4383 remove dsmgr dependency [`#168`](https://github.com/rdkcentral/tr69hostif/pull/168) +- RDKEMW-2629 [RDKE] Review and Cleanup tr69hostif module debug and error logs [`#167`](https://github.com/rdkcentral/tr69hostif/pull/167) +- RDKEMW-4334-InactiveApplications- tr181 parameter does not exist in data model [`#160`](https://github.com/rdkcentral/tr69hostif/pull/160) +- RDKEMW-3656 : tr69hostif Crash in mutex unlock (#156) [`#161`](https://github.com/rdkcentral/tr69hostif/pull/161) +- RDKEMW-3656 : tr69hostif Crash in mutex unlock [`#156`](https://github.com/rdkcentral/tr69hostif/pull/156) +- RDK-57360 [RDK-E] L2 test framework for tr69hostif - webpa path [`#147`](https://github.com/rdkcentral/tr69hostif/pull/147) +- 1.1.8 release changelog updates [`f762c8b`](https://github.com/rdkcentral/tr69hostif/commit/f762c8b689547f90328af5a628cd3fb4ca627eba) +- Update data-model-generic.xml [`84456dd`](https://github.com/rdkcentral/tr69hostif/commit/84456ddcb78733197fc7737796f4053b58ac900c) +- Hard stop for tr69hostif service during cleanup [`25a1451`](https://github.com/rdkcentral/tr69hostif/commit/25a14512db9b26453a4e9fd2e97ddf2cb9e36f59) + +#### [1.1.7](https://github.com/rdkcentral/tr69hostif/compare/1.1.6...1.1.7) + +> 14 May 2025 + +- REFPLTV-2816: Update xconf server to golang based [`#150`](https://github.com/rdkcentral/tr69hostif/pull/150) +- RDKEMW-3401: fetch failure in telemetry2_0 [`#148`](https://github.com/rdkcentral/tr69hostif/pull/148) +- RDK-56291 L2 Tests And Integration With CI for Remote Debugger Dynamic Updates [`#141`](https://github.com/rdkcentral/tr69hostif/pull/141) +- 1.1.7 release changelog updates [`4ad981f`](https://github.com/rdkcentral/tr69hostif/commit/4ad981f01d57a3a65e7aca2791b5d490be524e3b) +- Merge tag '1.1.6' into develop [`244c520`](https://github.com/rdkcentral/tr69hostif/commit/244c520c41af34b50a4d62fdffb1ff7bce04f309) + +#### [1.1.6](https://github.com/rdkcentral/tr69hostif/compare/1.1.5...1.1.6) + +> 30 April 2025 + +- RDK-56124-RDKE-Fix coverity issues in tr69hostif and profiles [`#105`](https://github.com/rdkcentral/tr69hostif/pull/105) +- RDKEMW-3545: Modified MigrationStatus Default value to NOT_NEEDED [`#127`](https://github.com/rdkcentral/tr69hostif/pull/127) +- 1.1.6 release changelog updates [`b6a0b0b`](https://github.com/rdkcentral/tr69hostif/commit/b6a0b0bd54e8593a77433b0f1b4dfb808a535cb7) +- Merge tag '1.1.5' into develop [`852cc26`](https://github.com/rdkcentral/tr69hostif/commit/852cc26965e03dbd20a5f3b0b55782126a45b87b) + +#### [1.1.5](https://github.com/rdkcentral/tr69hostif/compare/1.1.4...1.1.5) + +> 27 April 2025 + +- Revert "RDK-31923 : Added Enable parameter for Telemetry RFC. (#123)" [`#129`](https://github.com/rdkcentral/tr69hostif/pull/129) +- RDK-48829 [RDK-E] L2 test framework for tr69hostif [`#124`](https://github.com/rdkcentral/tr69hostif/pull/124) +- RDK-31923 : Added Enable parameter for Telemetry RFC. [`#123`](https://github.com/rdkcentral/tr69hostif/pull/123) +- RDKE-778: Add logs to rdmagent [`#121`](https://github.com/rdkcentral/tr69hostif/pull/121) +- 1.1.5 release changelog updates [`580f18d`](https://github.com/rdkcentral/tr69hostif/commit/580f18dfe6ffc25e4b6eabb889f118428cea8fc6) +- Merge tag '1.1.4' into develop [`7b0f8e0`](https://github.com/rdkcentral/tr69hostif/commit/7b0f8e0521d97021556f7e97c7cc8e22d9cfa137) + +#### [1.1.4](https://github.com/rdkcentral/tr69hostif/compare/1.1.3...1.1.4) + +> 8 April 2025 + +- RDK-51094 : XIONE-16968 : Add the new RFC config to data-model-generi… [`#115`](https://github.com/rdkcentral/tr69hostif/pull/115) +- Tr69hostif Sync [`#114`](https://github.com/rdkcentral/tr69hostif/pull/114) +- 1.1.4 release changelog updates [`5fbfe43`](https://github.com/rdkcentral/tr69hostif/commit/5fbfe431cd0d4a69033bdd136cf4637f32b4b9c0) +- RDK-51094 : XIONE-16968 : Add the new RFC config to data-model-generic.xml [`8196aaa`](https://github.com/rdkcentral/tr69hostif/commit/8196aaacc5a229cf1516d69a5dc8376f7cfb122e) +- Merge tag '1.1.3' into develop [`00f6a70`](https://github.com/rdkcentral/tr69hostif/commit/00f6a701419ca6c21563e485ecfe9a4543186af2) + +#### [1.1.3](https://github.com/rdkcentral/tr69hostif/compare/1.1.2...1.1.3) + +> 3 April 2025 + +- [RDKE] L2 Tests And Integration With CI for Remote Debugger Dynamic Updates [`#109`](https://github.com/rdkcentral/tr69hostif/pull/109) +- RDK-56451 [RDKE] Move tr69hostif L2 binary into common docker repo [`#106`](https://github.com/rdkcentral/tr69hostif/pull/106) +- RDKEMW-2234: Updated MigrationStatus to persistent dir [`#103`](https://github.com/rdkcentral/tr69hostif/pull/103) +- 1.1.3 release changelog updates [`fe5d15d`](https://github.com/rdkcentral/tr69hostif/commit/fe5d15ddda835fb13fc8bd163815a6edc360abeb) +- Update cov_build.sh [`a47d3a4`](https://github.com/rdkcentral/tr69hostif/commit/a47d3a45f626fe914eb235beb4c4dacf88731de2) +- Merge tag '1.1.2' into develop [`22fd47f`](https://github.com/rdkcentral/tr69hostif/commit/22fd47f6b9f069fed6121af9eac0319788f6d659) + +#### [1.1.2](https://github.com/rdkcentral/tr69hostif/compare/1.1.1...1.1.2) + +> 1 April 2025 + +- RDKEMW-2503 : Add RFC to data model- tr69hostif [`#79`](https://github.com/rdkcentral/tr69hostif/pull/79) +- rebase [`#100`](https://github.com/rdkcentral/tr69hostif/pull/100) +- RDKEMW-2234: Updated MigrationStatus tr181 param [`#96`](https://github.com/rdkcentral/tr69hostif/pull/96) +- 1.1.2 release changelog updates [`4697e26`](https://github.com/rdkcentral/tr69hostif/commit/4697e266261fb23b00b44a814b3d89d4ad3656ef) +- Merge tag '1.1.1' into develop [`2e87e9f`](https://github.com/rdkcentral/tr69hostif/commit/2e87e9f85e3c46957dd59927fce3637175736b3c) + +#### [1.1.1](https://github.com/rdkcentral/tr69hostif/compare/1.1.0...1.1.1) + +> 27 March 2025 + +- RDK-55702: Update the MW clients to use Power Manager Plugin [`#47`](https://github.com/rdkcentral/tr69hostif/pull/47) +- sync to develop [`#58`](https://github.com/rdkcentral/tr69hostif/pull/58) +- 1.1.1 release changelog updates [`1db7900`](https://github.com/rdkcentral/tr69hostif/commit/1db790041e0af21131182dd3d5c9d911253a83e2) +- Merge tag '1.1.0' into develop [`6f7faef`](https://github.com/rdkcentral/tr69hostif/commit/6f7faef0a12bd75bbd9a1f126f60610b278b70e4) + +#### [1.1.0](https://github.com/rdkcentral/tr69hostif/compare/1.0.14...1.1.0) + +> 27 March 2025 + +- RDK-52635 [RDKE-MW][tr69hostif] Remove all product/platform/region specific build time configs/variables/distro features [`#91`](https://github.com/rdkcentral/tr69hostif/pull/91) +- Revert "RDK-52635 [RDKE-MW][tr69hostif] Remove all product/platform/region specific build time configs/variables/distro features" [`#90`](https://github.com/rdkcentral/tr69hostif/pull/90) +- RDK-52635 [RDKE-MW][tr69hostif] Remove all product/platform/region specific build time configs/variables/distro features [`#69`](https://github.com/rdkcentral/tr69hostif/pull/69) +- Feature/rdk52635 [`#78`](https://github.com/rdkcentral/tr69hostif/pull/78) +- Merge [`#74`](https://github.com/rdkcentral/tr69hostif/pull/74) +- Merge [`#72`](https://github.com/rdkcentral/tr69hostif/pull/72) +- rebase [`#66`](https://github.com/rdkcentral/tr69hostif/pull/66) +- merge [`#59`](https://github.com/rdkcentral/tr69hostif/pull/59) +- Merge [`#52`](https://github.com/rdkcentral/tr69hostif/pull/52) +- Revert "Revert "RDK-52635 [RDKE-MW][tr69hostif] Remove all product/platform/region specific build time configs/variables/distro features"" [`93dccdf`](https://github.com/rdkcentral/tr69hostif/commit/93dccdfb662a00c113d909488be04e98cfcd3c20) +- Update hostIf_main.cpp [`df05ebd`](https://github.com/rdkcentral/tr69hostif/commit/df05ebdbffedbfd129ae68b32122a2b7d1280635) +- Update hostIf_main.cpp [`42d4d33`](https://github.com/rdkcentral/tr69hostif/commit/42d4d336432611ff5b9aba5871622558919e3010) + +#### [1.0.14](https://github.com/rdkcentral/tr69hostif/compare/1.0.13...1.0.14) + +> 26 March 2025 + +- RDK-56550 : Add new RFC value for LaunchDarkly env key [`#84`](https://github.com/rdkcentral/tr69hostif/pull/84) +- RDK-56451 [RDKE] Move tr69hostif L2 binary into common docker repo [`#82`](https://github.com/rdkcentral/tr69hostif/pull/82) +- RDK-56084 : Replace Script with rdm-agent for RRD Dynamic Profile [`#65`](https://github.com/rdkcentral/tr69hostif/pull/65) +- 1.0.14 release changelog updates [`6ffeb93`](https://github.com/rdkcentral/tr69hostif/commit/6ffeb93932575399dc910e74230d69999d4017f7) +- Merge tag '1.0.13' into develop [`0cf30c0`](https://github.com/rdkcentral/tr69hostif/commit/0cf30c03ebae0f3cab8041551b2b2b299d5e128f) +- RDK-56082: Addressing Review Comments [`89bf58a`](https://github.com/rdkcentral/tr69hostif/commit/89bf58aeea8828adde28a4ff8bf858bbfc642e27) + +#### [1.0.13](https://github.com/rdkcentral/tr69hostif/compare/1.0.12...1.0.13) + +> 25 March 2025 + +- RDK-56451 [RDKE] Move tr69hostif L2 binary into common docker repo [`#60`](https://github.com/rdkcentral/tr69hostif/pull/60) +- rebase topic branch [`#73`](https://github.com/rdkcentral/tr69hostif/pull/73) +- RDKEMW-2621:Default ReserveTTS RFC to true [`#68`](https://github.com/rdkcentral/tr69hostif/pull/68) +- 1.0.13 release changelog updates [`f56c066`](https://github.com/rdkcentral/tr69hostif/commit/f56c066f49c0f97be48efd3d011ac42136f609dd) +- Merge tag '1.0.12' into develop [`97eb199`](https://github.com/rdkcentral/tr69hostif/commit/97eb19993dc0220d362ea5c4602f292397d221ef) + +#### [1.0.12](https://github.com/rdkcentral/tr69hostif/compare/1.0.11...1.0.12) + +> 13 March 2025 + +- RDKEMW-2308: Secure wrapper API fixes [`#53`](https://github.com/rdkcentral/tr69hostif/pull/53) +- Rebase with develop [`#55`](https://github.com/rdkcentral/tr69hostif/pull/55) +- RDKEMW-1803: Add debugs for Mutex issue [`#54`](https://github.com/rdkcentral/tr69hostif/pull/54) +- Fix libsyswrapper to run in background [`033ce3c`](https://github.com/rdkcentral/tr69hostif/commit/033ce3c77f38e3c0b8b80b98b9a8184d942ca0ba) +- Fix libsyswrapper calls [`969dc69`](https://github.com/rdkcentral/tr69hostif/commit/969dc69d2bd1ad05f8597b009c91846cee3d7ea1) +- 1.0.12 release changelog updates [`4bd638b`](https://github.com/rdkcentral/tr69hostif/commit/4bd638ba5afb4a88143c18e2452694d14b6703ba) + +#### [1.0.11](https://github.com/rdkcentral/tr69hostif/compare/1.0.10...1.0.11) > 11 March 2025 -- RDK-56444: Define tr181 parameter and handlers for the IUI Version [`#44`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/44) -- Rebase from develop [`#49`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/49) -- RDKEMW-1524: Upgrade tr69hostif to libsoup-3.0 [`#48`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/48) -- Migrate tr69hostif to libsoup3 [`b5d1732`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/b5d173213a18e77e85efd4963af15b00442c701e) -- RDK-56444: Add IUI version as mandatory field [`017f1ee`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/017f1ee6acb556ba6c93b9c60cb3dd993196f32e) -- RDK-56444: Add IUI version as mandatory field [`4c04b1d`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/4c04b1d0ddc61cd292ec4eda19ce543f4d7c41b0) +- RDK-56444: Define tr181 parameter and handlers for the IUI Version [`#44`](https://github.com/rdkcentral/tr69hostif/pull/44) +- Rebase from develop [`#49`](https://github.com/rdkcentral/tr69hostif/pull/49) +- RDKEMW-1524: Upgrade tr69hostif to libsoup-3.0 [`#48`](https://github.com/rdkcentral/tr69hostif/pull/48) +- Migrate tr69hostif to libsoup3 [`b5d1732`](https://github.com/rdkcentral/tr69hostif/commit/b5d173213a18e77e85efd4963af15b00442c701e) +- RDK-56444: Add IUI version as mandatory field [`017f1ee`](https://github.com/rdkcentral/tr69hostif/commit/017f1ee6acb556ba6c93b9c60cb3dd993196f32e) +- RDK-56444: Add IUI version as mandatory field [`4c04b1d`](https://github.com/rdkcentral/tr69hostif/commit/4c04b1d0ddc61cd292ec4eda19ce543f4d7c41b0) -#### [1.0.10](https://github.com-venkat0557/rdkcentral/tr69hostif/compare/1.0.9...1.0.10) +#### [1.0.10](https://github.com/rdkcentral/tr69hostif/compare/1.0.9...1.0.10) > 6 March 2025 -- RDKEMW-1524: Upgrade tr69hostif to libsoup-3.0 [`#16`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/16) -- Rebase from develop [`#37`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/37) -- Rebase from develop [`#24`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/24) -- Rebase with develop [`#17`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/17) -- 1.0.10 release changelog updates [`edd483e`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/edd483ee04648fb081bff93ccc0d0b882653c6ce) -- Merge tag '1.0.9' into develop [`763605c`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/763605c3a2489875062e530327aa801e20ea81ab) -- Update http_server.cpp [`80a5044`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/80a5044813baeea57db9b9d505ac9522226d575d) +- RDKEMW-1524: Upgrade tr69hostif to libsoup-3.0 [`#16`](https://github.com/rdkcentral/tr69hostif/pull/16) +- Rebase from develop [`#37`](https://github.com/rdkcentral/tr69hostif/pull/37) +- Rebase from develop [`#24`](https://github.com/rdkcentral/tr69hostif/pull/24) +- Rebase with develop [`#17`](https://github.com/rdkcentral/tr69hostif/pull/17) +- 1.0.10 release changelog updates [`edd483e`](https://github.com/rdkcentral/tr69hostif/commit/edd483ee04648fb081bff93ccc0d0b882653c6ce) +- Merge tag '1.0.9' into develop [`763605c`](https://github.com/rdkcentral/tr69hostif/commit/763605c3a2489875062e530327aa801e20ea81ab) +- Update http_server.cpp [`80a5044`](https://github.com/rdkcentral/tr69hostif/commit/80a5044813baeea57db9b9d505ac9522226d575d) -#### [1.0.9](https://github.com-venkat0557/rdkcentral/tr69hostif/compare/1.0.8...1.0.9) +#### [1.0.9](https://github.com/rdkcentral/tr69hostif/compare/1.0.8...1.0.9) > 5 March 2025 -- RDKEMW-1803: Add debugs for Mutex issue [`#32`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/32) -- 1.0.9 release changelog updates [`2b1264e`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/2b1264ea3141e3a43165a6371fa363bfc6330696) -- Merge tag '1.0.8' into develop [`6c47ac4`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/6c47ac49bc702139b011cd44eb8e0c68d8a7ea2b) +- RDKEMW-1803: Add debugs for Mutex issue [`#32`](https://github.com/rdkcentral/tr69hostif/pull/32) +- 1.0.9 release changelog updates [`2b1264e`](https://github.com/rdkcentral/tr69hostif/commit/2b1264ea3141e3a43165a6371fa363bfc6330696) +- Merge tag '1.0.8' into develop [`6c47ac4`](https://github.com/rdkcentral/tr69hostif/commit/6c47ac49bc702139b011cd44eb8e0c68d8a7ea2b) -#### [1.0.8](https://github.com-venkat0557/rdkcentral/tr69hostif/compare/1.0.7...1.0.8) +#### [1.0.8](https://github.com/rdkcentral/tr69hostif/compare/1.0.7...1.0.8) > 5 March 2025 -- RDKEMW-2015 Reboot is not happening when initiating reboot using RPC.RebootNow [`f76d8b0`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/f76d8b0dd44f37faa9f4f097e3c8d179948d9ccd) -- 1.0.8 release changelog updates [`fd82254`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/fd82254dbb56648e41ee1cf39dc3724ba6416159) -- Merge tag '1.0.7' into develop [`48cac37`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/48cac376d46d1796963e5b6e563b719b7ffa95f0) +- RDKEMW-2015 Reboot is not happening when initiating reboot using RPC.RebootNow [`f76d8b0`](https://github.com/rdkcentral/tr69hostif/commit/f76d8b0dd44f37faa9f4f097e3c8d179948d9ccd) +- 1.0.8 release changelog updates [`fd82254`](https://github.com/rdkcentral/tr69hostif/commit/fd82254dbb56648e41ee1cf39dc3724ba6416159) +- Merge tag '1.0.7' into develop [`48cac37`](https://github.com/rdkcentral/tr69hostif/commit/48cac376d46d1796963e5b6e563b719b7ffa95f0) -#### [1.0.7](https://github.com-venkat0557/rdkcentral/tr69hostif/compare/1.0.6...1.0.7) +#### [1.0.7](https://github.com/rdkcentral/tr69hostif/compare/1.0.6...1.0.7) > 3 March 2025 -- RDKVREFPLT-4470:Enable https for webpa.rdkcentral.com [`#21`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/21) -- RDK-55468 : tr69hsotif L2 test framework [`#5`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/5) -- rebase from develop [`#20`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/20) -- DELIA-65776 : Removal of unused attributes [`#14`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/14) -- RDKE-697: [MEMCR] AppHibernate RFC XML tags are missed in data-model.xml [`#11`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/11) -- RDK-55339: Add debug services RFC [`#10`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/10) -- 1.0.7 release changelog updates [`41777d2`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/41777d2466b09db9a975a5c7ccf25ab1496d651c) -- RDKE-697: [RDKE][MEMCR] AppHibernate RFC XML tags are missed in data-model.xml. [`28d01fd`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/28d01fd31d0dd2493126936521567190ea83b077) -- Merge tag '1.0.6' into develop [`0b3f03f`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/0b3f03f65014dea97c4d64c71fd184f974cbf642) +- RDKVREFPLT-4470:Enable https for webpa.rdkcentral.com [`#21`](https://github.com/rdkcentral/tr69hostif/pull/21) +- RDK-55468 : tr69hsotif L2 test framework [`#5`](https://github.com/rdkcentral/tr69hostif/pull/5) +- rebase from develop [`#20`](https://github.com/rdkcentral/tr69hostif/pull/20) +- DELIA-65776 : Removal of unused attributes [`#14`](https://github.com/rdkcentral/tr69hostif/pull/14) +- RDKE-697: [MEMCR] AppHibernate RFC XML tags are missed in data-model.xml [`#11`](https://github.com/rdkcentral/tr69hostif/pull/11) +- RDK-55339: Add debug services RFC [`#10`](https://github.com/rdkcentral/tr69hostif/pull/10) +- 1.0.7 release changelog updates [`41777d2`](https://github.com/rdkcentral/tr69hostif/commit/41777d2466b09db9a975a5c7ccf25ab1496d651c) +- RDKE-697: [RDKE][MEMCR] AppHibernate RFC XML tags are missed in data-model.xml. [`28d01fd`](https://github.com/rdkcentral/tr69hostif/commit/28d01fd31d0dd2493126936521567190ea83b077) +- Merge tag '1.0.6' into develop [`0b3f03f`](https://github.com/rdkcentral/tr69hostif/commit/0b3f03f65014dea97c4d64c71fd184f974cbf642) #### 1.0.6 > 30 January 2025 -- RDKECMF-216 Fix names in native_full_build workflow [`#2`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/2) -- RDKE-622 Fix warnings in tr69hostif [`#1`](https://github.com-venkat0557/rdkcentral/tr69hostif/pull/1) -- Import of source (develop) [`db913d7`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/db913d7e78c379f68c2743350abf00b185314946) -- 1.0.6 release changelog updates [`67c968f`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/67c968f937dc7680bfd7f48196a6e0438d7faba6) -- Fix comments in native_full_build workflow [`b7e46af`](https://github.com-venkat0557/rdkcentral/tr69hostif/commit/b7e46af54c78bba2dd9fecfd8fb75766756aedd8) +- RDKECMF-216 Fix names in native_full_build workflow [`#2`](https://github.com/rdkcentral/tr69hostif/pull/2) +- RDKE-622 Fix warnings in tr69hostif [`#1`](https://github.com/rdkcentral/tr69hostif/pull/1) +- Import of source (develop) [`db913d7`](https://github.com/rdkcentral/tr69hostif/commit/db913d7e78c379f68c2743350abf00b185314946) +- 1.0.6 release changelog updates [`67c968f`](https://github.com/rdkcentral/tr69hostif/commit/67c968f937dc7680bfd7f48196a6e0438d7faba6) +- Fix comments in native_full_build workflow [`b7e46af`](https://github.com/rdkcentral/tr69hostif/commit/b7e46af54c78bba2dd9fecfd8fb75766756aedd8) diff --git a/configure.ac b/configure.ac index 2800a2fae..25ca20954 100644 --- a/configure.ac +++ b/configure.ac @@ -212,6 +212,30 @@ AC_ARG_ENABLE([notification], ], [echo "Notification support is disabled"]) +AC_ARG_ENABLE([t2api], + AS_HELP_STRING([--enable-t2api],[enables telemetry]), + [ + case "${enableval}" in + yes) IS_TELEMETRY2_ENABLED=true + T2_EVENT_FLAG=" -DT2_EVENT_ENABLED ";; + no) IS_TELEMETRY2_ENABLED=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-t2enable]) ;; + esac + ], + [echo "telemetry is disabled"]) +AM_CONDITIONAL([IS_TELEMETRY2_ENABLED], [test x$IS_TELEMETRY2_ENABLED = xtrue]) +AC_SUBST(T2_EVENT_FLAG) + +AC_ARG_ENABLE([powercontroller], +[ --enable-powercontroller Enable linking WPEFrameworkPowerController], +[case "${enableval}" in + yes) powercontroller=true ;; + no) powercontroller=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-powercontroller]) ;; +esac],[powercontroller=false]) +AM_CONDITIONAL([POWERCONTROLLER_ENABLE], [test x$powercontroller = xtrue]) + + AC_ARG_ENABLE([rf4ce], AS_HELP_STRING([--enable-rf4ce],[enable X_RDKCENTRAL_COM RF4CE profile (default is no)]), diff --git a/cov_build.sh b/cov_build.sh index e1e4fdb6c..a9e92048b 100644 --- a/cov_build.sh +++ b/cov_build.sh @@ -9,10 +9,16 @@ cd $ROOT git clone https://github.com/rdkcentral/rfc.git cd rfc autoreconf -i -./configure --enable-rfctool=yes --enable-tr181set=yes +./configure --enable-rfctool=yes --enable-tr181set=yes --enable-tr69hostif=yes cd rfcapi -make librfcapi_la_CPPFLAGS="-I/usr/include/cjson" +make librfcapi_la_CPPFLAGS="-I/usr/include/cjson -DUSE_IARMBUS" make install +cd ../tr181api +cp /usr/include/cjson/cJSON.h ./ +cp /usr/local/include/wdmp-c/wdmp-c.h ./ +make AM_CXXFLAGS="-DUSE_TR69HOSTIF" && make install +cd ../utils +make && make install #Build yajl - tr69 alone needs this specific version cd $ROOT @@ -28,10 +34,11 @@ cd $ROOT rm -rf rdk-halif-device_settings rm -rf rdkvhal-devicesettings-raspberrypi4 rm -rf iarmbus +rm -rf remote_debugger git clone https://github.com/rdkcentral/rdk-halif-device_settings.git git clone https://github.com/rdkcentral/rdkvhal-devicesettings-raspberrypi4.git git clone https://github.com/rdkcentral/iarmbus.git - +git clone https://github.com/rdkcentral/remote_debugger.git # Build devicesettings version with fixes for native build and use that as a stub # TODO This is not present in mainline versions. Component maintainers will have to provide this in future. @@ -51,18 +58,26 @@ echo "Building IARMBus stubs" cd $WORKDIR cd ./src/unittest/stubs g++ -fPIC -shared -o libIARMBus.so iarm_stubs.cpp -I$WORKDIR/src/hostif/parodusClient/pal -I$WORKDIR/src/unittest/stubs -I$WORKDIR/src/hostif/parodusClient/waldb -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$WORKDIR/src/hostif/include -I$WORKDIR/src/hostif/profiles/DeviceInfo -I$WORKDIR/src/hostif/parodusClient/pal -fpermissive +g++ -fPIC -shared -o libWPEFrameworkPowerController.so powerctrl_stubs.cpp -I$WORKDIR/src/unittest/stubs -fpermissive cp libIARMBus.so /usr/local/lib cp libIBus.h /usr/local/include cp libIARM.h /usr/local/include +cp libWPEFrameworkPowerController.so /usr/local/lib/libWPEFrameworkPowerController.so + echo "##### Building tr69hostif module" cd $WORKDIR sed -i '/PKG_CHECK_MODULES(\[PROCPS\], \[libproc >= 3.2.8\])/s/^/#/' ./configure.ac rm -f ./src/unittest/stubs/rdk_debug.h autoreconf -i -./configure --enable-libsoup3=yes +./configure --enable-IPv6=yes -make AM_CXXFLAGS="-I$WORKDIR/src/unittest/stubs -I$WORKDIR/src/hostif/include -I/usr/include/cjson -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$WORKDIR/src/hostif/handlers/include -I$WORKDIR/src/hostif/parodusClient/waldb -I$WORKDIR/src/hostif/profiles/DeviceInfo -I/usr/include/cjson -I$WORKDIR/src/hostif/profiles/Time -I$WORKDIR/src/hostif/profiles/Device -I/usr/include/libsoup-3.0 -I/usr/include/yajl -I$WORKDIR/src/hostif/profiles/STBService -I$WORKDIR/src/unittest/stubs/ds -I/usr/devicesettings/ds -I/usr/local/include -I$WORKDIR/src/hostif/profiles/IP -I$WORKDIR/src/hostif/profiles/Ethernet -I/usr/local/include/rbus -I$WORKDIR/src/hostif/parodusClient/pal -I/usr/rdk-halif-device_settings/include -I/usr/local/include/libparodus -I/usr/local/include -I/usr/rdkvhal-devicesettings-raspberrypi4 -I/usr/local/include/ -I/usr/include/yajl -I/usr/tinyxml2 -I/usr/devicesettings/ds -I/$WORKDIR/src/hostif/httpserver/include -DLIBSOUP3_ENABLE" \ -AM_LDFLAGS="-L/usr/local/lib -lrbus -lsecure_wrapper -lcurl -lrfcapi -lrdkloggers -llibparodus -lnanomsg -lIARMBus -lds -ldshalcli -ldshalsrv -lwrp-c -lwdmp-c -lprocps -ltrower-base64 -lcimplog -lsoup-3.0 -L/usr/lib/x86_64-linux-gnu -lyajl -L/usr/local/lib/x86_64-linux-gnu -ltinyxml2" CXXFLAGS="-fpermissive -DPARODUS_ENABLE" +make AM_CXXFLAGS="-I$WORKDIR/src/unittest/stubs -I$WORKDIR/src/hostif/include -I/usr/include/cjson -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$WORKDIR/src/hostif/handlers/include -I$WORKDIR/src/hostif/parodusClient/waldb -I$WORKDIR/src/hostif/profiles/DeviceInfo -I/usr/include/cjson -I$WORKDIR/src/hostif/profiles/Time -I$WORKDIR/src/hostif/profiles/Device -I/usr/include/libsoup-3.0 -I/usr/include/yajl -I$WORKDIR/src/hostif/profiles/STBService -I$WORKDIR/src/unittest/stubs/ds -I/usr/devicesettings/ds -I/usr/local/include -I$WORKDIR/src/hostif/profiles/IP -I$WORKDIR/src/hostif/profiles/Ethernet -I/usr/local/include/rbus -I$WORKDIR/src/hostif/parodusClient/pal -I/usr/rdk-halif-device_settings/include -I/usr/local/include/libparodus -I/usr/local/include -I/usr/rdkvhal-devicesettings-raspberrypi4 -I/usr/local/include/ -I/usr/include/yajl -I/usr/tinyxml2 -I/usr/devicesettings/ds -I/$WORKDIR/src/hostif/httpserver/include -I/usr/remote_debugger/src/ -DIPV6_SUPPORT" \ +AM_LDFLAGS="-L/usr/local/lib -lrbus -lsecure_wrapper -lcurl -lrfcapi -lrdkloggers -llibparodus -lglib-2.0 -lnanomsg -lIARMBus -lWPEFrameworkPowerController -lds -ldshalcli -ldshalsrv -lwrp-c -lwdmp-c -lprocps -ltrower-base64 -lcimplog -lsoup-3.0 -L/usr/lib/x86_64-linux-gnu -lyajl -L/usr/local/lib/x86_64-linux-gnu -ltinyxml2" CXXFLAGS="-fpermissive -DPARODUS_ENABLE -DUSE_REMOTE_DEBUGGER" make install +cd ./src/hostif/parodusClient/pal/mock-parodus/ +sh mock_parodus_build.sh + +ln -sf /usr/local/bin/tr181 /usr/bin/tr181Set +rbuscli set Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable boolean true diff --git a/dependent_rdk_pkg_installer.sh b/dependent_rdk_pkg_installer.sh new file mode 100644 index 000000000..d4bc1afd4 --- /dev/null +++ b/dependent_rdk_pkg_installer.sh @@ -0,0 +1,111 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2024 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################## + +# Clone and build rbus +export RBUS_ROOT=/usr +export RBUS_INSTALL_DIR=${RBUS_ROOT}/local +mkdir -p $RBUS_INSTALL_DIR +cd $RBUS_ROOT + + +WORKDIR=/opt/WORKDIR +mkdir -p $WORKDIR + +cd $WORKDIR +git clone https://github.com/xmidt-org/trower-base64.git +cd trower-base64 +meson setup build +ninja -C build +ninja -C build install +cd $WORKDIR +rm -rf trower-base64 + +# cJson flavor used in RDK stack +cd $WORKDIR +git clone https://github.com/DaveGamble/cJSON.git +cd cJSON +mkdir build +cd build +cmake .. +make && make install +cd $WORKDIR +rm -rf cJSON + +# Include WDMP package +cd $WORKDIR +git clone https://github.com/xmidt-org/wdmp-c.git +cd wdmp-c +sed -i '/WDMP_ERR_SESSION_IN_PROGRESS/a\ WDMP_ERR_INTERNAL_ERROR,\n WDMP_ERR_DEFAULT_VALUE,' src/wdmp-c.h +cmake -H. -Bbuild -DBUILD_FOR_DESKTOP=ON -DCMAKE_BUILD_TYPE=Debug +make -C build && make -C build install +cd $WORKDIR +rm -rf wdmp-c + +# Install dependencies of libparodus +cd $WORKDIR +git clone https://github.com/nanomsg/nanomsg.git +cd nanomsg +mkdir build +cd build +cmake .. +cmake --build . +cmake --build . --target install +cd $WORKDIR +rm -rf nanomsg + +git clone https://github.com/xmidt-org/cimplog.git +cd cimplog +git checkout 8a5fb3c2f182241d17f5342bea5b7688c28cd1fd +mkdir build +cd build +cmake .. +make && make install +cd $WORKDIR +rm -rf cimplog + + +cd $WORKDIR +git clone https://github.com/xmidt-org/wrp-c.git +cd wrp-c +git checkout 9587e8db33dbbfcd9b78ef66cc2eaf16dfb9afcf +# replace 7a98138f27f27290e680bf8fbf1f8d1b089bf138 with 445880108a1d171f755ff6ac77e03fbebbb23729 in CMakeLists.txt +# Message pack revision used in libparadous is not buildable with latest gcc versions +sed -i 's/7a98138f27f27290e680bf8fbf1f8d1b089bf138/445880108a1d171f755ff6ac77e03fbebbb23729/g' CMakeLists.txt +mkdir build +cd build +cmake .. +make && make install +cd $WORKDIR +rm -rf wrp-c + +cd $WORKDIR +git clone https://github.com/xmidt-org/libparodus.git +cd libparodus +# replace 7a98138f27f27290e680bf8fbf1f8d1b089bf138 with 445880108a1d171f755ff6ac77e03fbebbb23729 in CMakeLists.txt +# Message pack revision used in libparadous is not buildable with latest gcc versions +sed -i 's/7a98138f27f27290e680bf8fbf1f8d1b089bf138/445880108a1d171f755ff6ac77e03fbebbb23729/g' CMakeLists.txt +mkdir build +cd build +cmake .. +make && make install +cd $WORKDIR +rm -rf libparodus + + +#rtrouted -f -l DEBUG diff --git a/partners_defaults.json b/partners_defaults.json index 8693518bb..1d9396de9 100644 --- a/partners_defaults.json +++ b/partners_defaults.json @@ -38,15 +38,15 @@ "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.DefaultSupportedLocales" : "" }, "community" : { - "Device.Time.NTPServer1" : "time.com", - "Device.Time.NTPServer2" : "time1.com", - "Device.Time.NTPServer3" : "time2.com", - "Device.Time.NTPServer4" : "time3.com", - "Device.Time.NTPServer5" : "time4.com", + "Device.Time.NTPServer1" : "time.google.com", + "Device.Time.NTPServer2" : "time1.google.com", + "Device.Time.NTPServer3" : "time2.google.com", + "Device.Time.NTPServer4" : "time3.google.com", + "Device.Time.NTPServer5" : "time4.google.com", "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName" : "community", "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerProductName" : "", "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.NetflixESNprefix" : "", - "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfUrl" : "https://xconf.rdkcentral.com:19092", + "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfUrl" : "https://xconf.rdkcentral.com", "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfRecoveryUrl" : "", "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.SsrUrl" : "", "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LSA.Enable" : "False", diff --git a/run_l2.sh b/run_l2.sh index 0669d99b8..b9610cc2a 100644 --- a/run_l2.sh +++ b/run_l2.sh @@ -23,7 +23,28 @@ export top_srcdir=`pwd` RESULT_DIR="/tmp/l2_test_report" mkdir -p "$RESULT_DIR" -cp ./src/integrationtest/conf/data-model-generic.xml /tmp/data-model.xml +apt-get update && apt-get install -y iproute2 + + + cp ./src/hostif/parodusClient/waldb/data-model/data-model-tv.xml /etc/data-model-tv.xml + cp ./src/hostif/parodusClient/waldb/data-model/data-model-generic.xml /etc/data-model-generic.xml + cp ./src/hostif/parodusClient/waldb/data-model/data-model-stb.xml /etc/data-model-stb.xml + +sed -i '/ModelName/ {n; n; a\ + +}' /etc/data-model-stb.xml + +dos2unix /etc/data-model-stb.xml + +echo "RDK_PROFILE=STB" > /etc/device.properties + +echo "VERSION=99.99.15.07" >> /version.txt +echo "Proto|http" >> /opt/fwdnldstatus.txt +echo "Status|Download In Progress" >> /opt/fwdnldstatus.txt +echo "DnldFile|TESTIMAGE_DEV.bin" >> /opt/fwdnldstatus.txt +echo "DnldURL|https://mockserver.tv/Images" >> /opt/fwdnldstatus.txt +echo "FwUpdateState|Download complete" >> /opt/fwdnldstatus.txt + cp ./src/integrationtest/conf/mgrlist.conf /etc/ mkdir -p /opt/secure/RFC/ @@ -41,8 +62,10 @@ if [ ! -z "$pid" ]; then kill -9 `pidof tr69hostif` fi -/usr/local/bin/tr69hostif -c /etc/mgrlist.conf -d /etc/debug.ini -p 10999 -s 11999 | tee /opt/logs/tr69hostIf.log.0 & +/usr/local/bin/tr69hostif -c /etc/mgrlist.conf -p 10999 -s 11999 | tee /opt/logs/tr69hostIf.log.0 & pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/bootup_sequence.json test/functional-tests/tests/test_bootup_sequence.py pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/handlers_communications.json test/functional-tests/tests/test_handlers_communications.py +pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/deviceip.json test/functional-tests/tests/tr69hostif_deviceip.py +pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/webpa.json test/functional-tests/tests/tr69hostif_webpa.py diff --git a/run_ut.sh b/run_ut.sh index c6143381c..23a4b3e65 100644 --- a/run_ut.sh +++ b/run_ut.sh @@ -18,10 +18,36 @@ # SPDX-License-Identifier: Apache-2.0 ############################################################################ +WORKDIR=`pwd` +sh dependent_rdk_pkg_installer.sh +export ROOT=/usr + +cd $ROOT +rm -rf remote_debugger +rm -rf rdk-halif-device_settings +rm -rf rdkvhal-devicesettings-raspberrypi4 +git clone https://github.com/rdkcentral/remote_debugger.git +git clone https://github.com/rdkcentral/rdk-halif-device_settings.git +git clone https://github.com/rdkcentral/rdkvhal-devicesettings-raspberrypi4.git + +cd $WORKDIR +ls -l /usr/local/include/libparodus/ +ENABLE_COV=false + +if [ "x$1" = "x--enable-cov" ]; then + echo "Enabling coverage options" + export CXXFLAGS="-g -O0 -fprofile-arcs -ftest-coverage" + export CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage" + export LDFLAGS="-lgcov --coverage" + ENABLE_COV=true +fi + apt-get update apt-get -y install libtinyxml2-dev apt-get -y install libsoup-3.0-dev - +apt-get -y install libprocps-dev +apt-get -y install libnanomsg-dev +apt-get -y install iproute2 sed '/<\/model>/d; /<\/dm:document>/d' ./src/hostif/parodusClient/waldb/data-model/data-model-tv.xml > ./src/hostif/parodusClient/waldb/data-model/data-model-merged.xml sed '/> ./src/hostif/parodusClient/waldb/data-model/data-model-merged.xml @@ -32,12 +58,34 @@ cp ./src/unittest/stubs/rfcdefaults.ini /tmp/rfcdefaults.ini mkdir /opt/secure mkdir /opt/secure/RFC +mkdir -p /opt/secure/reboot/ +mkdir -p /opt/www/authService/ +mkdir -p /tmp/webpa +mkdir -p /opt/persistent/ +mkdir -p /etc/rfcdefaults +mkdir -p /etc/apparmor.d +mkdir -p /opt/secure/persistent/ +mkdir -p /etc/rrd/ cp ./src/unittest/stubs/tr181store.ini /opt/secure/RFC/tr181store.ini +cp ./src/integrationtest/conf/bootstrap.ini /opt/secure/RFC/ +cp ./src/integrationtest/conf/rfcVariable.ini /opt/secure/RFC/ cp partners_defaults.json /etc/partners_defaults.json cp ./src/unittest/stubs/partners_defaults_device.json /etc/partners_defaults_device.json cp ./src/unittest/stubs/fwdnldstatus.txt /opt/fwdnldstatus.txt - -export TOP_DIR=`pwd` +cp ./src/integrationtest/conf/mgrlist.conf /etc/mgrlist.conf +cp ./src/unittest/stubs/remote_debugger.json /etc/rrd/remote_debugger.json +touch /tmp/timeReceivedNTP +touch /tmp/webpa/start_time +touch /opt/persistent/firstNtpTime +touch /etc/rfcdefaults/rfcdefaults.ini +touch /opt/XRE_container_enable /opt/dab-enable +touch /opt/.ntpEnabled +touch /var/tmp/rssh.pid +cat /version.txt +rm -rf /version.txt +echo "Method|" >> /opt/fwdnldstatus.txt + +export TOP_DIR=$WORKDIR cd ./src/ automake --add-missing @@ -50,27 +98,85 @@ make clean echo "TOP_DIR = $TOP_DIR" +echo "**** Compiling handlers gtest ****" +cd $TOP_DIR/src/hostif/handlers/src/gtest +rm handlers_gtest +sed -i '/getCurrentTime/,/^ *}/d' ../../../src/hostIf_utils.cpp +make clean +make +./handlers_gtest +echo "********************" + + echo "**** Compiling data model gtest ****" cd $TOP_DIR/src/hostif/parodusClient/gtest rm dm_gtest +#sed -i '/getCurrentTime/,/^ *}/d' ../../src/hostIf_utils.cpp make ./dm_gtest echo "********************" +echo "**** Compiling httpserver gtest ****" +cd $TOP_DIR/src/hostif/httpserver/src/gtest +rm httpserver_gtest +#sed -i '$a void getCurrentTime(struct timespec *timer)\n{\n clock_gettime(CLOCK_REALTIME, timer);\n}' ../../../src/hostIf_utils.cpp +#sed -i '/getCurrentTime/,/^ *}/d' ../../src/hostIf_utils.cpp +make clean +make +./httpserver_gtest +echo "********************" -lcov --capture --directory . --output-file coverage.info -lcov --remove coverage.info '/usr/*' --output-file coverage.filtered.info -genhtml coverage.filtered.info --output-directory out +echo "**** Compiling src gtest ****" +cd $TOP_DIR/src/hostif/src/gtest +rm src_gtest +sed -i '$a void getCurrentTime(struct timespec *timer)\n{\n clock_gettime(CLOCK_REALTIME, timer);\n}' ../hostIf_utils.cpp +make clean +make +./src_gtest +echo "********************" + +echo "**** Compiling DHCPv4 gtest ****" +cd $TOP_DIR/src/hostif/profiles/DHCPv4/gtest +rm dhcpv4_gtest +make +./dhcpv4_gtest +echo "********************" + +echo "**** Compiling Device gtest ****" +cd $TOP_DIR/src/hostif/profiles/Device/gtest +rm device_gtest +make +./device_gtest +echo "********************" + +echo "**** Compiling Ethernet gtest ****" +cd $TOP_DIR/src/hostif/profiles/Ethernet/gtest +rm ethernet_gtest +make +./ethernet_gtest +echo "********************" +echo "**** Compiling Time gtest ****" +cd $TOP_DIR/src/hostif/profiles/Time/gtest +rm time_gtest +make +./time_gtest +echo "********************" echo "**** Compiling DeviceInfo gtest ****" cd $TOP_DIR/src/hostif/profiles/DeviceInfo/gtest -rm devieInfo_gtest +cp ../../../../unittest/stubs/rfc.properties /etc/rfc.properties +rm devieInfo_gtest /opt/www/authService/partnerId3.dat make ./devieInfo_gtest echo "********************" +cd $TOP_DIR -lcov --capture --directory . --output-file coverage.info -lcov --remove coverage.info '/usr/*' --output-file coverage.filtered.info -genhtml coverage.filtered.info --output-directory out +if [ "$ENABLE_COV" = true ]; then + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info '/usr/*' '*/gtest/*' '*/mocks/*' --output-file filtered.info + lcov --extract filtered.info '*/src/hostif/httpserver/*' '*/src/hostif/parodusClient/*' '*/src/hostif/src/*' '*/src/hostif/profiles/DHCPv4/*' '*/src/hostif/profiles/Device/*' '*/src/hostif/profiles/DeviceInfo/*' '*/src/hostif/profiles/Ethernet/*' '*/src/hostif/profiles/Time/*' --output-file tr69hostif_coverage.info + lcov --list tr69hostif_coverage.info +fi + diff --git a/src/Makefile.am b/src/Makefile.am index 18ce02e94..21fef82e9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -56,6 +56,8 @@ else NEXUS_LIB = endif + + if WITH_WIFI_PROFILE AM_CXXFLAGS += -DUSE_WIFI_PROFILE AM_CXXFLAGS += -I$(top_srcdir)/src/hostif/profiles/wifi @@ -98,6 +100,9 @@ AM_LDFLAGS = $(GLIB_LDFLAGS) $(GLIB_LIBS) \ -lds -ldshalcli endif +if POWERCONTROLLER_ENABLE +AM_LDFLAGS += -lWPEFrameworkPowerController +endif AM_CFLAGS = $(GLIB_CFLAGS) $(GTHREAD_CFLAGS) AM_CPPFLAGS = $(GLIB_CFLAGS) $(GTHREAD_CFLAGS) @@ -115,6 +120,11 @@ else AM_LDFLAGS += $(SYSTEMD_SDNOTIFY_LDFLAGS) endif +if IS_TELEMETRY2_ENABLED +AM_CXXFLAGS += $(T2_EVENT_FLAG) +AM_LDFLAGS += -ltelemetry_msgsender -lt2utils +endif + bin_PROGRAMS = tr69hostif backgroundrun tr69hostif_SOURCES = $(top_srcdir)/src/hostif/src/hostIf_main.cpp $(top_srcdir)/src/hostif/src/hostIf_utils.cpp tr69hostif_SOURCES += $(top_srcdir)/src/hostif/src/IniFile.cpp diff --git a/src/configure.ac b/src/configure.ac index fc5a6577a..5a4d58d68 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -42,20 +42,35 @@ AC_FUNC_REALLOC # Check for GLib 2.0 PKG_CHECK_MODULES([GLIB], [glib-2.0]) -# This enables libsoup-3 support -AC_ARG_ENABLE([libsoup3], -[ --enable-libsoup3 Turn on libsoup-3 support], -[case "${enableval}" in - yes) libsoup3=true ;; - no) libsoup3=false ;; - *) AC_MSG_ERROR([bad value ${enableval} for --enable-libsoup3]) ;; -esac],[libsoup3=false]) -AM_CONDITIONAL([LIBSOUP3_ENABLE], [test x$libsoup3 = xtrue]) + + +AC_ARG_ENABLE([t2api], + AS_HELP_STRING([--enable-t2api],[enables telemetry]), + [ + case "${enableval}" in + yes) IS_TELEMETRY2_ENABLED=true + T2_EVENT_FLAG=" -DT2_EVENT_ENABLED ";; + no) IS_TELEMETRY2_ENABLED=false ;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-t2enable]) ;; + esac + ], + [echo "telemetry is disabled"]) +AM_CONDITIONAL([IS_TELEMETRY2_ENABLED], [test x$IS_TELEMETRY2_ENABLED = xtrue]) +AC_SUBST(T2_EVENT_FLAG) + # Generate the Makefile AC_CONFIG_FILES([ - hostif/parodusClient/gtest/Makefile \ - hostif/profiles/DeviceInfo/gtest/Makefile]) + hostif/parodusClient/gtest/Makefile + hostif/httpserver/src/gtest/Makefile + hostif/src/gtest/Makefile + hostif/profiles/DHCPv4/gtest/Makefile + hostif/profiles/Device/gtest/Makefile + hostif/profiles/Ethernet/gtest/Makefile + hostif/profiles/Time/gtest/Makefile + hostif/profiles/DeviceInfo/gtest/Makefile + hostif/handlers/src/gtest/Makefile + ]) # Generate the configure script AC_OUTPUT diff --git a/src/hostif/handlers/Makefile.am b/src/hostif/handlers/Makefile.am index 155cae827..3f73b9d7b 100644 --- a/src/hostif/handlers/Makefile.am +++ b/src/hostif/handlers/Makefile.am @@ -44,13 +44,8 @@ AM_CXXFLAGS = -I$(top_srcdir)/src/hostif/include \ -I=/usr/include/rdk/ds/ \ -I=/usr/include/rdk/ds-hal/ \ $(XRDK_RF4CE_PROFILE_FLAG) \ - -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/rbus/ - -if LIBSOUP3_ENABLE -AM_CXXFLAGS += -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/libsoup-3.0 -DLIBSOUP3_ENABLE -else -AM_CXXFLAGS += -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/libsoup-2.4 -endif + -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/rbus/ \ + -I=/usr/include/libsoup-3.0/ AM_CXXFLAGS += "-std=c++11" $(PROCPS_CFLAGS) @@ -84,6 +79,8 @@ AM_CXXFLAGS += -DBTMGR_ENABLE_IARM_INTERFACE AM_CXXFLAGS += -I$(top_srcdir)/src/hostif/profiles/DeviceInfo endif + + if WITH_HWSELFTEST_PROFILE AM_CXXFLAGS += $(HWSELFTEST_PROFILE_FLAG) endif @@ -92,11 +89,17 @@ if WITH_SNMP_ADAPTER AM_CXXFLAGS += -DSNMP_ADAPTER_ENABLED -I$(top_srcdir)/src/hostif/snmpAdapter endif -AM_LDFLAGS = $(GLIB_LIBS) $(G_THREAD_LIBS) $(SOUP_LIBS) $(PROCPS_LIBS) -lIARMBus -lyajl -lds -ldshalcli -ldbus-1 +AM_LDFLAGS = $(GLIB_LIBS) $(G_THREAD_LIBS) $(SOUP_LIBS) $(PROCPS_LIBS) -lIARMBus -lyajl -lds -ldshalcli -ldbus-1 -lsoup-3.0 -lgobject-2.0 -lsecure_wrapper if WIFI_CLIENT_ROAMING AM_CXXFLAGS += -DWIFI_CLIENT_ROAMING endif +if IS_TELEMETRY2_ENABLED +AM_CXXFLAGS += $(T2_EVENT_FLAG) +AM_LDFLAGS += -ltelemetry_msgsender -lt2utils +endif + + noinst_LTLIBRARIES = libMsgHandlers.la libMsgHandlers_la_SOURCES = src/hostIf_IARM_ReqHandler.cpp \ src/hostIf_msgHandler.cpp \ diff --git a/src/hostif/handlers/include/hostIf_XREClient_ReqHandler.h b/src/hostif/handlers/include/hostIf_XREClient_ReqHandler.h index 64f922c2f..2f4cb38c0 100755 --- a/src/hostif/handlers/include/hostIf_XREClient_ReqHandler.h +++ b/src/hostif/handlers/include/hostIf_XREClient_ReqHandler.h @@ -50,6 +50,7 @@ #include "hostIf_msgHandler.h" #include "hostIf_updateHandler.h" #include "hostIf_main.h" +#include "secure_wrapper.h" /** * @brief This class provides the interface for getting XRE request handler information. @@ -78,6 +79,8 @@ class XREClientReqHandler : public msgHandler static msgHandler* getInstance(); }; +int set_Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow(HOSTIF_MsgData_t *stMsgData); +int get_Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow(HOSTIF_MsgData_t *stMsgData); #endif /* HOSTIF_XRECLIENT_REQHANDLER_H_ */ /* End of HOSTIF_XRECLIENT_REQHANDLER_H_ doxygen group */ /** diff --git a/src/hostif/handlers/include/hostIf_msgHandler.h b/src/hostif/handlers/include/hostIf_msgHandler.h index cc9512838..a385cf586 100644 --- a/src/hostif/handlers/include/hostIf_msgHandler.h +++ b/src/hostif/handlers/include/hostIf_msgHandler.h @@ -98,6 +98,8 @@ void hostIf_Print_msgData(HOSTIF_MsgData_t *stMsgData); void hostIf_Free_stMsgData (HOSTIF_MsgData_t *stMsgData); +void paramValueToString(const HOSTIF_MsgData_t *stMsgData, char *paramValueStr, size_t strSize); + bool hostIf_initalize_ConfigManger(); bool hostIf_ConfigProperties_Init(); class msgHandler { diff --git a/src/hostif/handlers/include/hostIf_rbus_Dml_Provider.h b/src/hostif/handlers/include/hostIf_rbus_Dml_Provider.h index 2cb9f5cf1..322e6766c 100644 --- a/src/hostif/handlers/include/hostIf_rbus_Dml_Provider.h +++ b/src/hostif/handlers/include/hostIf_rbus_Dml_Provider.h @@ -48,11 +48,22 @@ #ifndef HOSTIF_RBUS_DML_PROVIDER_H_ #define HOSTIF_RBUS_DML_PROVIDER_H_ +#ifdef GTEST_ENABLE +#include "rbus_value.h" +#include "rbus.h" +#endif + void init_rbus_dml_provider(); int setRbusStringParam(const char *paramName, char* paramValue); int getRbusStringParam(const char *paramName, char** paramValue); +#ifdef GTEST_ENABLE +rbusError_t TR_Dml_EventSubHandler(rbusHandle_t handle, rbusEventSubAction_t action, const char* eventName, rbusFilter_t filter, int32_t interval, bool* autoPublish); +rbusError_t TR_Dml_GetHandler(rbusHandle_t handle, rbusProperty_t inProperty, rbusGetHandlerOptions_t* opts); +rbusError_t TR_Dml_SetHandler(rbusHandle_t handle, rbusProperty_t inProperty, rbusSetHandlerOptions_t* opts); +#endif + #endif /* HOSTIF_RBUS_DML_PROVIDER_H_ */ /* End of HOSTIF_RBUS_DML_PROVIDER_H_ API doxygen group */ diff --git a/src/hostif/handlers/src/gtest/Makefile.am b/src/hostif/handlers/src/gtest/Makefile.am new file mode 100644 index 000000000..279fb4966 --- /dev/null +++ b/src/hostif/handlers/src/gtest/Makefile.am @@ -0,0 +1,39 @@ +################################################################################ +# Copyright 2024 Comcast Cable Communications Management, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +AUTOMAKE_OPTIONS = subdir-objects + +# Define the program name and the source files +bin_PROGRAMS = handlers_gtest + +# Define the include directories + +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -DYOCTO_BUILD -DUSE_DEV_PROPERTIES_CONF -DUSE_REMOTE_DEBUGGER -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I$(TOP_DIR)/src/hostif/handlers/include -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/hostif/httpserver/include -I$(TOP_DIR)/src/hostif/handlers/src -I/usr/include/rbus -I/usr/local/include/rbus -Isrc/unittest/stubs/rbus/include/ -I$(TOP_DIR)/src/hostif/profiles/Time -I$(TOP_DIR)/src/hostif/profiles/Device -I$(TOP_DIR)/src/hostif/profiles/IP -I$(TOP_DIR)/src/hostif/profiles/STBService -I/usr/rdk-halif-device_settings/include/ -I/usr/rdkvhal-devicesettings-raspberrypi4/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$(TOP_DIR)/src/hostif/profiles/Ethernet -I/usr/remote_debugger/src/ -I/usr/local/include/libparodus/ -I/usr/local/include/wrp-c/ -I$(TOP_DIR)/src/hostif/parodusClient/startParodus/ -I$(TOP_DIR)/src/hostif/profiles/DHCPv4 -I/usr/include/libsoup-3.0 + +# Define the libraries to link against +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lglib-2.0 -llibparodus -lwrp-c -lnanomsg -lmsgpackc -ltrower-base64 -lcimplog -lsoup-3.0 + +# Define the compiler flags +COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) -fprofile-arcs -ftest-coverage + +handlers_gtest_SOURCES = handlers_test.cpp $(TOP_DIR)/src/hostif/parodusClient/startParodus/startParodus.cpp $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_NotificationHandler.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_notification.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_attribute.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_parameter.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/libpd.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_adapter.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_msgHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_XrdkCentralT2_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_DeviceClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus_Process.cpp $(TOP_DIR)/src/hostif/profiles/Ethernet/Device_Ethernet_Interface.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_DisplayDevice.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_EthernetClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_TimeClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface.cpp $(TOP_DIR)/src/hostif/profiles/Time/Device_Time.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_updateHandler.cpp $(TOP_DIR)/src/hostif/profiles/Device/x_rdk_profile.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_dsClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_rbus_Dml_Provider.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Capabilities.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_SPDIF.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_VideoDecoder.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_AudioOutput.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_HDMI.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_VideoOutput.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface_Stats.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_ActivePort.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Diagnostics_IPPing.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface_IPv4Address.cpp $(TOP_DIR)/src/hostif/handlers/src/x_rdk_req_handler.cpp $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/unittest/stubs/wdmp-c.c $(TOP_DIR)/src/unittest/stubs/wdmp_internal.c $(TOP_DIR)/src/hostif/httpserver/src/http_server.cpp $(TOP_DIR)/src/hostif/httpserver/src/request_handler.cpp $(TOP_DIR)/src/hostif/httpserver/src/XrdkCentralComRFCVar.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.cpp $(TOP_DIR)/src/unittest/stubs/ds/libprocps.cpp $(TOP_DIR)/src/unittest/stubs/file_writer.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_DHCPv4Client_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.cpp + +# Apply common properties to each program +handlers_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) +handlers_gtest_LDADD = $(COMMON_LDADD) +handlers_gtest_CXXFLAGS = $(COMMON_CXXFLAGS) diff --git a/src/hostif/handlers/src/gtest/handlers_test.cpp b/src/hostif/handlers/src/gtest/handlers_test.cpp new file mode 100644 index 000000000..11faa7765 --- /dev/null +++ b/src/hostif/handlers/src/gtest/handlers_test.cpp @@ -0,0 +1,1530 @@ +/* + * Copyright 2024 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include "dm_stubs.h" +#include "startParodus.h" +#include "file_writer.h" +#include "webpa_notification.h" +#include "webpa_parameter.h" +#include "webpa_adapter.h" +#include "libpd.h" +#include "webpa_attribute.h" +#include "rbus_value.h" +#include "hostIf_tr69ReqHandler.h" +#include "hostIf_utils.h" +#include "wrp-c.h" +#include "x_rdk_req_handler.h" +#include "hostIf_rbus_Dml_Provider.h" +#include "rbus_value.h" +#include "rbus.h" +#include "hostIf_XrdkCentralT2_ReqHandler.h" +#include "hostIf_TimeClient_ReqHandler.h" +#include "hostIf_DeviceClient_ReqHandler.h" +#include "hostIf_EthernetClient_ReqHandler.h" +#include "hostIf_IPClient_ReqHandler.h" +#include "hostIf_DHCPv4Client_ReqHandler.h" + + +#include "waldb.h" +#include "wdmp-c.h" + +using namespace std; + + +#include +#include + + +#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/" +#define GTEST_DEFAULT_RESULT_FILENAME "datamodel_gtest_report.json" +#define GTEST_REPORT_FILEPATH_SIZE 128 + +extern GHashTable* paramMgrhash; + +std::mutex mtx_httpServerThreadDone; +std::condition_variable cv_httpServerThreadDone; +bool httpServerThreadDone = false; +GThread *HTTPServerThread = NULL; +char *HTTPServerName = (char *)"HTTPServerThread"; +GError *httpError = NULL; +GHashTable* paramMgrhash = NULL; +T_ARGLIST argList = {{'\0'}, 0}; + +extern int (*convertRbus2hostIfDataTypeFunc()) (rbusValueType_t type, HostIf_ParamType_t* pParamType); + + +TEST(handlersTest, handleGetMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.X_RDK_WebPA_DNSText.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + X_rdk_req_hdlr* reqHandler = static_cast(X_rdk_req_hdlr::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, handleSetMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.X_RDK_WebPA_DNSText.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + strncpy(param.paramValue, "fabric.xmidt.comcast.net", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + X_rdk_req_hdlr* reqHandler = static_cast(X_rdk_req_hdlr::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, convertRbus2hostIfDataType) { + HostIf_ParamType_t paramType; + + EXPECT_EQ(convertRbus2hostIfDataTypeFunc()(RBUS_BOOLEAN, ¶mType), 0); + EXPECT_EQ(convertRbus2hostIfDataTypeFunc()(RBUS_INT8, ¶mType), 0); + EXPECT_EQ(convertRbus2hostIfDataTypeFunc()(RBUS_UINT8, ¶mType), 0); + EXPECT_EQ(convertRbus2hostIfDataTypeFunc()(RBUS_INT64, ¶mType), 0); + EXPECT_EQ(convertRbus2hostIfDataTypeFunc()(RBUS_STRING, ¶mType), 0); + EXPECT_EQ(convertRbus2hostIfDataTypeFunc()(RBUS_DATETIME, ¶mType), 0); +} + +TEST(handlersTest, TR_Dml_EventSubHandler) { + HostIf_ParamType_t paramType; + rbusHandle_t handle; + rbusEventSubAction_t action; + const char* eventName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType"; + rbusFilter_t filter; + int32_t interval = 60; + bool autoPublish = false; + + rbusError_t rc = TR_Dml_EventSubHandler(handle, action, eventName, filter, interval, &autoPublish); + EXPECT_EQ(rc, RBUS_ERROR_SUCCESS); +} + +TEST(handlersTest, TR_Dml_GetHandler) { + //MockRbusProperty mockProp = { "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.Enable" }; + //rbusProperty_t testProp = (rbusProperty_t)&mockProp; + rbusProperty_t testProp; + + rbusHandle_t handle; + rbusGetHandlerOptions_t opts = {}; + + rbusError_t rc = TR_Dml_GetHandler(handle, testProp, &opts); + EXPECT_EQ(rc, 2); +} + +TEST(handlersTest, setRbusStringParam) { + const char *paramName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType"; + char* paramValue = "testdata"; + + int rc = setRbusStringParam(paramName, paramValue); + EXPECT_EQ(rc, -1); +} + +TEST(handlersTest, getRbusStringParam) { + const char *paramName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType"; + char* paramValue = nullptr; + + int rc = getRbusStringParam(paramName, ¶mValue); + EXPECT_EQ(rc, -1); +} + +TEST(handlersTest, XrdkCentralT2handleSetMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.X_RDKCENTRAL-COM_T2.ReportProfiles", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + strncpy(param.paramValue, "testprofile", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + XRdkCentralT2* reqHandler = static_cast(XRdkCentralT2::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, XrdkCentralT2handleGetMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.X_RDKCENTRAL-COM_T2.ReportProfiles", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + XRdkCentralT2* reqHandler = static_cast(XRdkCentralT2::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, TimeClientReqHandler_handleGetMsg_Enable) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.Time.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + TimeClientReqHandler* reqHandler = static_cast(TimeClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + + +TEST(handlersTest, TimeClientReqHandler_handleGetMsg_Status) { + write_on_file("/tmp/ntp_status", "ntp status"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.Time.Status", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + TimeClientReqHandler* reqHandler = static_cast(TimeClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + EXPECT_STREQ(param.paramValue, "ntp status"); + } +} + +TEST(handlersTest, TimeClientReqHandler_handleGetMsg_LocalTimeZone) { + write_on_file("/tmp/ntp_status", "ntp status"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.Time.LocalTimeZone", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + TimeClientReqHandler* reqHandler = static_cast(TimeClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, TimeClientReqHandler_handleGetMsg_CurrentLocalTime) { + write_on_file("/tmp/ntp_status", "ntp status"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.Time.CurrentLocalTime", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + TimeClientReqHandler* reqHandler = static_cast(TimeClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, TimeClientReqHandler_handleGetMsg_X_RDK_CurrentUTCTime) { + write_on_file("/tmp/ntp_status", "ntp status"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.Time.X_RDK_CurrentUTCTime", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + TimeClientReqHandler* reqHandler = static_cast(TimeClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, TimeClientReqHandler_handleSetMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.Time.NTPServer5", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_SRC_RFC; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "override_time4.com", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + TimeClientReqHandler* reqHandler = static_cast(TimeClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + + +TEST(handlersTest, TimeClientReqHandler_handleGetAttributesMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.Time.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + TimeClientReqHandler* reqHandler = static_cast(TimeClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetAttributesMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, TimeClientReqHandler_handleSetAttributesMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.Time.NTPServer4", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "override_time3.com", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + TimeClientReqHandler* reqHandler = static_cast(TimeClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetAttributesMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.SsrUrl", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_SRC_RFC; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "https://ssr.ccp.xcal.tv", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_FirmwareDownloadStatus) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "Download Started", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_FirmwareDownloadProtocol) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadProtocol", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "http", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_FirmwareDownloadURL) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadURL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "https://xconf.xdp.eu-1.xcal.tv", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_PreferredGatewayType) { + write_on_file("/opt/prefered-gateway", "192.168.1.1"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_PreferredGatewayType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_set_xOpsDMUploadLogsNow) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.Logging.xOpsDMUploadLogsNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "true", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_ForwardSSHEnable) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ForwardSSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_DownloadStatus) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.DownloadStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_IPRemoteSupportEnable) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_IPRemoteSupport.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleSetMsg_PartnerId) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "global", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.SsrUrl", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_SRC_RFC; + param.requestor = HOSTIF_SRC_RFC; + + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_PreferredGatewayType) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_PreferredGatewayType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_Manufacturer) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.Manufacturer", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_ManufacturerOUI) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.ManufacturerOUI", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, -2); + } +} + + + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_ModelName) { + write_on_file("/tmp/.model", "SKY"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.ModelName", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + EXPECT_STREQ(param.paramValue, "SKY"); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_Description) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.Description", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_HardwareVersion) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.HardwareVersion", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, NOK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_SoftwareVersion) { + writeToTr181storeFile("VERSION", "99.99.15.07", "/version.txt", Plain); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.SoftwareVersion", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } + std::remove("/version.txt"); +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_MigrationStatus) { + write_on_file("/opt/secure/persistent/MigrationStatus", "NEEDED"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.Migration.MigrationStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + EXPECT_STREQ(param.paramValue, "NEEDED"); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_IUI_Version) { + write_on_file("/tmp/.iuiVersion", "4.4"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM.IUI.Version", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + EXPECT_STREQ(param.paramValue, "4.4"); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_UpTime) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.UpTime", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_FirstUseDate) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.FirstUseDate", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_FirmwareFilename) { + write_on_file("/tmp/currently_running_image_name", "ELTE11MWR_DEV_develop_20250808222826_NG"); + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareFilename", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + EXPECT_EQ(ret, OK); + EXPECT_STREQ(param.paramValue, "ELTE11MWR_DEV_develop_20250808222826_NG"); + } + std::remove("/tmp/currently_running_image_name"); +} + +TEST(handlersTest, DeviceClientReqHandler_handleGetMsg_FirmwareDownloadStatus) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + DeviceClientReqHandler* reqHandler = static_cast(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) + { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DeviceClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleSetAttributesMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleSetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(EthernetClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleSetAttributesMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(IPClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(IPClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleSetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DHCPv4ClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DHCPv4ClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DHCPv4ClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DHCPv4ClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DHCPv4ClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleSetAttributesMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <(DHCPv4ClientReqHandler::getInstance()); + if(reqHandler) { + int ret = reqHandler->handleGetAttributesMsg(¶m); + cout << "msgData.paramValue = " << param.paramValue <set_xRDKDownloadManager_InstallPackage(stMsgData); } + else if (strcasecmp(stMsgData->paramName,X_RDKDownloadManager_DownloadStatus) == 0) + { + ret = pIface->set_xRDKDownloadManager_DownloadStatus(stMsgData); + } else if (strcasecmp(stMsgData->paramName,IPREMOTE_SUPPORT) == 0) { ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportEnable(stMsgData); @@ -486,6 +490,11 @@ int DeviceClientReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) { ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_BootStatus(stMsgData); } + + else if(strcasecmp(stMsgData->paramName,"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.getProfileData") == 0) + { + ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggergetProfileData(stMsgData); + } else if (strcasecmp(stMsgData->paramName,"Device.DeviceInfo.X_RDKCENTRAL-COM_PreferredGatewayType") == 0) { ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType(stMsgData); @@ -522,6 +531,14 @@ int DeviceClientReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) { ret = pIface->get_Device_DeviceInfo_SoftwareVersion(stMsgData); } + else if (strcasecmp(stMsgData->paramName,"Device.DeviceInfo.MigrationPreparer.MigrationReady") == 0) + { + ret = pIface->get_Device_DeviceInfo_MigrationPreparer_MigrationReady(stMsgData); + } + else if (strcasecmp(stMsgData->paramName,"Device.DeviceInfo.Migration.MigrationStatus") == 0) + { + ret = pIface->get_Device_DeviceInfo_Migration_MigrationStatus(stMsgData); + } else if (strcasecmp(stMsgData->paramName,IUI_VERSION) == 0) { ret = pIface->get_Device_DeviceInfo_IUI_Version(stMsgData); diff --git a/src/hostif/handlers/src/hostIf_IARM_ReqHandler.cpp b/src/hostif/handlers/src/hostIf_IARM_ReqHandler.cpp index 76dd14c55..049c037c8 100644 --- a/src/hostif/handlers/src/hostIf_IARM_ReqHandler.cpp +++ b/src/hostif/handlers/src/hostIf_IARM_ReqHandler.cpp @@ -36,7 +36,12 @@ #include "libIBus.h" #include "libIARM.h" #include "sysMgr.h" +#ifdef RDKV_TR69 #include "pwrMgr.h" +#else +#include "power_controller.h" +#include +#endif #ifdef SNMP_ADAPTER_ENABLED #include "hostIf_SNMPClient_ReqHandler.h" #endif @@ -46,7 +51,10 @@ #include "safec_lib.h" #define X_RDK_RFC_DEEPSLEEP_ENABLE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Power.DeepSleepNotification.Enable" - +#define RETRYSLEEP (300 * 1000) //Retry sleep +#ifndef RDKV_TR69 +static bool IsPwrCtlInt = false; +#endif static bool TR69_HostIf_Mgr_Init(); static bool TR69_HostIf_Mgr_Connect(); static bool TR69_HostIf_Mgr_Get_RegisterCall(); @@ -56,7 +64,12 @@ static IARM_Result_t _Settr69HostIfMgr(void *arg); static IARM_Result_t _SetAttributestr69HostIfMgr(void *arg); static IARM_Result_t _GetAttributestr69HostIfMgr(void *arg); static IARM_Result_t _RegisterForEventstr69HostIfMgr(void *arg); +#ifdef RDKV_TR69 static void _hostIf_EventHandler(const char *, IARM_EventId_t, void *, size_t); +#else +static void _hostIf_EventHandler(const PowerController_PowerState_t currentState, + const PowerController_PowerState_t newState, void* userdata); +#endif //---------------------------------------------------------------------- // hostIf_IARM_IF_Start: This shall be use to initialize and register // the hostIf application to IARM bus. @@ -73,10 +86,13 @@ bool hostIf_IARM_IF_Start() ret = true; /* Initialize Managers */ msgHandler *pMsgHandler; + #ifdef RDKV_TR69 pMsgHandler = DSClientReqHandler::getInstance(); pMsgHandler->init(); + #endif pMsgHandler = DeviceClientReqHandler::getInstance(); pMsgHandler->init(); + #ifdef SNMP_ADAPTER_ENABLED pMsgHandler = SNMPClientReqHandler::getInstance(); @@ -88,6 +104,40 @@ bool hostIf_IARM_IF_Start() return ret; } +#ifndef RDKV_TR69 +void hostIf_getPwrContInterface() +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + + /*TODO: remove this sleep after fix METROL-1045*/ + sleep(10);//added sleep wait for the WPEframework active. + msgHandler *pMsgHandler; + pMsgHandler = DSClientReqHandler::getInstance(); + pMsgHandler->init(); + + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d]: start PowerController_Init().. \n", __FUNCTION__, __LINE__); + PowerController_Init(); + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d]: completed PowerController_Init().. \n", __FUNCTION__, __LINE__); + while(true) + { + if(POWER_CONTROLLER_ERROR_NONE == PowerController_Connect()) + { + hostIf_DeviceInfo::getInstance(0)->setPowerConInterface(true); + IsPwrCtlInt = true; + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s] Got the powercontroller interface.. IsPwrCtlInt = %s\n", __FUNCTION__, __FILE__ , (IsPwrCtlInt?"true":"false")); + break; + } + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s] Retry after %d usec..\n", __FUNCTION__, __FILE__, RETRYSLEEP); + usleep(RETRYSLEEP); //retry after RETRYSLEEP milli seconds. + + } + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s] Registering power mode change callback..\n", __FUNCTION__, __FILE__); + PowerController_RegisterPowerModeChangedCallback(_hostIf_EventHandler, nullptr); + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s] Registered power mode change callback..\n", __FUNCTION__, __FILE__); + + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); +} +#endif //---------------------------------------------------------------------- //Initialization: This shall be initialized tr69 application to IARM bus. @@ -106,6 +156,19 @@ RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"########################################## return false; } RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s()] Success 'IARM_Bus_Init(%s)'.\n", __FUNCTION__, IARM_BUS_TR69HOSTIFMGR_NAME); + #ifndef RDKV_TR69 + // Get powercontroller thunder client interface in separate thread + std::thread pwrThread(hostIf_getPwrContInterface); + if(pwrThread.joinable()) + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d]: created getPwrContInterface thread.. \n", __FUNCTION__, __LINE__); + pwrThread.detach(); // Detach the thread to run independently + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d]: Failed to create getPwrContInterface thread.. \n", __FUNCTION__, __LINE__); + } + #endif RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return true; @@ -161,8 +224,9 @@ static bool TR69_HostIf_Mgr_Get_RegisterCall() /* Notification RPC:*/ IARM_Bus_RegisterEvent(IARM_BUS_TR69HOSTIFMGR_EVENT_MAX); - IARM_Bus_RegisterEventHandler(IARM_BUS_PWRMGR_NAME,IARM_BUS_PWRMGR_EVENT_MODECHANGED, _hostIf_EventHandler); - + #ifdef RDKV_TR69 + IARM_Bus_RegisterEventHandler(IARM_BUS_PWRMGR_NAME,IARM_BUS_PWRMGR_EVENT_MODECHANGED, _hostIf_EventHandler); + #endif RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return ret; } @@ -274,6 +338,26 @@ static IARM_Result_t tr69hostIfMgr_Stop(void) { RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s] Failed to IARM_Bus_Term(), return with Error code: %d\n", __FUNCTION__, err); } + #ifndef RDKV_TR69 + if (IsPwrCtlInt) + { + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s] UnRegistering power mode change callback..\n", __FUNCTION__, __FILE__); + PowerController_UnRegisterPowerModeChangedCallback(_hostIf_EventHandler); + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s] UnRegistered power mode change callback..\n", __FUNCTION__, __FILE__); + + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d]: start PowerController_Term().. \n", __FUNCTION__, __LINE__); + PowerController_Term(); + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d]: completed PowerController_Term().. \n", __FUNCTION__, __LINE__); + hostIf_DeviceInfo::getInstance(0)->setPowerConInterface(false); + IsPwrCtlInt = false; + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%d]: setPowerConInterface flag to false. and IsPwrCtlInt=%s\n", __FUNCTION__, __LINE__, (IsPwrCtlInt?"true":"false")); + + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d]: No PowerController interface .. IsPwrCtlInt = %d\n", __FUNCTION__, __LINE__, IsPwrCtlInt); + } + #endif RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return err; } @@ -392,6 +476,8 @@ static IARM_Result_t _Gettr69HostIfMgr(void *arg) //---------------------------------------------------------------------- //_hostIf_EventHandler: This is to listen the IARM events and handles. //---------------------------------------------------------------------- + +#ifdef RDKV_TR69 static void _hostIf_EventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); @@ -434,6 +520,46 @@ static void _hostIf_EventHandler(const char *owner, IARM_EventId_t eventId, void } RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); } +#else +static void _hostIf_EventHandler(const PowerController_PowerState_t currentState, + const PowerController_PowerState_t newState, void* userdata) +{ + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + errno_t rc = -1; + HOSTIF_MsgData_t stRfcData = {0}; + rc=strcpy_s(stRfcData.paramName,sizeof(stRfcData.paramName), X_RDK_RFC_DEEPSLEEP_ENABLE); + if(rc!=EOK) + { + ERR_CHK(rc); + } + if((hostIf_DeviceInfo::getInstance(0)->get_xRDKCentralComRFC(&stRfcData) == OK) && (strncmp(stRfcData.paramValue, "true", sizeof("true")) == 0)) + { + const char *event_time = NULL; + + if((newState == POWER_STATE_STANDBY_DEEP_SLEEP) && + (currentState != POWER_STATE_STANDBY_DEEP_SLEEP)) + { + std::string event_time_string = std::to_string(std::time(nullptr)); + event_time = event_time_string.c_str(); + NotificationHandler::getInstance()->push_device_deepsleep_notifications("device-enter-deepsleep-state", event_time); + } + else if((newState != POWER_STATE_STANDBY_DEEP_SLEEP) && + (currentState == POWER_STATE_STANDBY_DEEP_SLEEP)) + { + std::string event_time_string = std::to_string(std::time(nullptr)); + event_time = event_time_string.c_str(); + NotificationHandler::getInstance()->push_device_deepsleep_notifications("device-exit-deepsleep-state", event_time); + } + } + else + { + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s] RFC Parameter (%s) is disabled, so not sending DeepSleep notification. \n", + __FUNCTION__, X_RDK_RFC_DEEPSLEEP_ENABLE ); + } + + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); +} +#endif /** @} */ /** @} */ diff --git a/src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp b/src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp index 614086b16..9f5a0cb7a 100644 --- a/src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp +++ b/src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp @@ -1,3 +1,4 @@ + /* * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: @@ -46,8 +47,11 @@ #include "Device_IP.h" #include "Device_IP_Diagnostics_IPPing.h" #include "safec_lib.h" +#include "secure_wrapper.h" #include +#define MAX_IFCS 256 + std::mutex IPClientReqHandler::m_mutex; IPClientReqHandler* IPClientReqHandler::pInstance = NULL; updateCallback IPClientReqHandler::mUpdateCallback = NULL; @@ -425,6 +429,34 @@ void IPClientReqHandler::registerUpdateCallback(updateCallback cb) mUpdateCallback = cb; } +void getIPIfcIDs(unsigned int *ifindexes) { + int count = 0; + FILE *fp = v_secure_popen("r", "ls /sys/class/net"); + if (!fp) { + perror("popen"); + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s:%d Failed to open /sys/class/net contents\n", __FILE__, __LINE__); + return; + } + + char iface[256]; + while (fgets(iface, sizeof(iface), fp)) { + iface[strcspn(iface, "\n")] = 0; + + //char command[512]; + //snprintf(command, sizeof(command), "cat /sys/class/net/%s/ifindex", iface); + + FILE *ifindex_fp = v_secure_popen("r", "cat /sys/class/net/%s/ifindex", iface); + if (ifindex_fp) { + char buffer[64]; + if (fgets(buffer, sizeof(buffer), ifindex_fp)) { + ifindexes[count++] = atoi(buffer); + } + v_secure_pclose(ifindex_fp); + } + } + v_secure_pclose(fp); +} + void IPClientReqHandler::checkForUpdates() { if (mUpdateCallback == 0) @@ -449,28 +481,34 @@ void IPClientReqHandler::checkForUpdates() sendAddRemoveEvents (mUpdateCallback, interfaceNumberOfEntries, curNumOfIPInterface, objectPath); } - for (int i = 1; i <= interfaceNumberOfEntries; i++) + unsigned int ifindexes[MAX_IFCS]; + getIPIfcIDs(ifindexes); + for (int i = 0; i < interfaceNumberOfEntries && i < MAX_IFCS; i++) { - int ipv4AddressNumberOfEntries = hostIf_IPInterface::getInstance (i)->getIPv4AddressNumberOfEntries (); - RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s:%d] ipv4AddressNumberOfEntries = %d, curNumOfInterfaceIPv4Addresses[%d] = %d\n", - __FILE__, __FUNCTION__, __LINE__, ipv4AddressNumberOfEntries, i, curNumOfInterfaceIPv4Addresses[i]); - sprintf (objectPath, "Device.IP.Interface.%d.IPv4Address.", i); - sendAddRemoveEvents (mUpdateCallback, ipv4AddressNumberOfEntries, curNumOfInterfaceIPv4Addresses[i], objectPath); + + if (ifindexes[i] > 0 && ifindexes[i] < sizeof(curNumOfInterfaceIPv4Addresses)/sizeof(curNumOfInterfaceIPv4Addresses[0])) { + int ipv4AddressNumberOfEntries = hostIf_IPInterface::getInstance (ifindexes[i])->getIPv4AddressNumberOfEntries (); + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s:%d] ipv4AddressNumberOfEntries = %d, curNumOfInterfaceIPv4Addresses[%d] = %d\n", + __FILE__, __FUNCTION__, __LINE__, ipv4AddressNumberOfEntries, ifindexes[i], curNumOfInterfaceIPv4Addresses[ifindexes[i]]); + sprintf (objectPath, "Device.IP.Interface.%d.IPv4Address.", ifindexes[i]); + sendAddRemoveEvents (mUpdateCallback, ipv4AddressNumberOfEntries, curNumOfInterfaceIPv4Addresses[ifindexes[i]], objectPath); #ifdef IPV6_SUPPORT - int ipv6AddressNumberOfEntries = hostIf_IPInterface::getInstance (i)->getIPv6AddressNumberOfEntries (); - RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s:%d] ipv6AddressNumberOfEntries = %d, curNumOfInterfaceIPv6Addresses[%d] = %d\n", - __FILE__, __FUNCTION__, __LINE__, ipv6AddressNumberOfEntries, i, curNumOfInterfaceIPv6Addresses[i]); - sprintf (objectPath, "Device.IP.Interface.%d.IPv6Address.", i); - sendAddRemoveEvents (mUpdateCallback, ipv6AddressNumberOfEntries, curNumOfInterfaceIPv6Addresses[i], objectPath); - - int ipv6PrefixNumberOfEntries = hostIf_IPInterface::getInstance (i)->getIPv6PrefixNumberOfEntries (); - RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s:%d] ipv6PrefixNumberOfEntries = %d, curNumOfInterfaceIPv6Prefixes[%d] = %d\n", - __FILE__, __FUNCTION__, __LINE__, ipv6PrefixNumberOfEntries, i, curNumOfInterfaceIPv6Prefixes[i]); - sprintf (objectPath, "Device.IP.Interface.%d.IPv6Prefix.", i); - sendAddRemoveEvents (mUpdateCallback, ipv6PrefixNumberOfEntries, curNumOfInterfaceIPv6Prefixes[i], objectPath); - + if (ifindexes[i] < sizeof(curNumOfInterfaceIPv6Addresses)/sizeof(curNumOfInterfaceIPv6Addresses[0])) { + int ipv6AddressNumberOfEntries = hostIf_IPInterface::getInstance (ifindexes[i])->getIPv6AddressNumberOfEntries (); + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s:%d] ipv6AddressNumberOfEntries = %d, curNumOfInterfaceIPv6Addresses[%d] = %d\n", + __FILE__, __FUNCTION__, __LINE__, ipv6AddressNumberOfEntries, ifindexes[i], curNumOfInterfaceIPv6Addresses[ifindexes[i]]); + sprintf (objectPath, "Device.IP.Interface.%d.IPv6Address.", ifindexes[i]); + sendAddRemoveEvents (mUpdateCallback, ipv6AddressNumberOfEntries, curNumOfInterfaceIPv6Addresses[ifindexes[i]], objectPath); + + int ipv6PrefixNumberOfEntries = hostIf_IPInterface::getInstance (ifindexes[i])->getIPv6PrefixNumberOfEntries (); + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s:%d] ipv6PrefixNumberOfEntries = %d, curNumOfInterfaceIPv6Prefixes[%d] = %d\n", + __FILE__, __FUNCTION__, __LINE__, ipv6PrefixNumberOfEntries, ifindexes[i], curNumOfInterfaceIPv6Prefixes[ifindexes[i]]); + sprintf (objectPath, "Device.IP.Interface.%d.IPv6Prefix.", ifindexes[i]); + sendAddRemoveEvents (mUpdateCallback, ipv6PrefixNumberOfEntries, curNumOfInterfaceIPv6Prefixes[ifindexes[i]], objectPath); + } #endif // IPV6_SUPPORT + } } hostIf_IP::releaseLock(); diff --git a/src/hostif/handlers/src/hostIf_WiFi_ReqHandler.cpp b/src/hostif/handlers/src/hostIf_WiFi_ReqHandler.cpp index 33c48e292..1b4be8168 100644 --- a/src/hostif/handlers/src/hostIf_WiFi_ReqHandler.cpp +++ b/src/hostif/handlers/src/hostIf_WiFi_ReqHandler.cpp @@ -255,6 +255,44 @@ int WiFiReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) const char *pSetting; const int maxSSID_Instances = 1; int instanceNum = 0; + #ifdef RDKV_TR69 + const int maxRadioInstances = 1; + int radioIndex = 1; + if (strcasecmp(stMsgData->paramName,"Device.WiFi.RadioNumberOfEntries") == 0) + { + stMsgData->instanceNum = maxRadioInstances; + hostIf_WiFi *pIface = hostIf_WiFi::getInstance(maxRadioInstances); + + if(!pIface) + { + return NOK; + } + + ret = pIface->get_Device_WiFi_RadioNumberOfEntries(stMsgData); + } + else if (strcasecmp(stMsgData->paramName,"Device.WiFi.SSIDNumberOfEntries") == 0) + { + stMsgData->instanceNum = maxSSID_Instances; + hostIf_WiFi *pIface = hostIf_WiFi::getInstance(maxSSID_Instances); + + if(!pIface) + { + return NOK; + } + + ret = pIface->get_Device_WiFi_SSIDNumberOfEntries(stMsgData); + } + else if (strcasecmp(stMsgData->paramName,"Device.WiFi.AccessPointNumberOfEntries") == 0) + { + stMsgData->instanceNum = 0; + hostIf_WiFi *pIface = hostIf_WiFi::getInstance(stMsgData->instanceNum); + if(!pIface) + { + return NOK; + } + ret = pIface->get_Device_WiFi_AccessPointNumberOfEntries(stMsgData); + } + #else if (strcasecmp(stMsgData->paramName,"Device.WiFi.AccessPointNumberOfEntries") == 0) { @@ -268,6 +306,7 @@ int WiFiReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) ret = pIface->get_Device_WiFi_AccessPointNumberOfEntries(stMsgData); } + #endif else if (strcasecmp(stMsgData->paramName,"Device.WiFi.EndPointNumberOfEntries") == 0) { hostIf_WiFi *pIface = hostIf_WiFi::getInstance (1); @@ -288,6 +327,179 @@ int WiFiReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) } ret = pIface->get_Device_WiFi_EnableWiFi(stMsgData); } + #ifdef RDKV_TR69 + else if (matchComponent(stMsgData->paramName, "Device.WiFi.Radio", &pSetting, instanceNum)) + { + if ((instanceNum <= 0) || (instanceNum > maxRadioInstances)) + { + return NOK; + } + + stMsgData->instanceNum = instanceNum; + hostIf_WiFi_Radio *pWifiRadio = hostIf_WiFi_Radio::getInstance(stMsgData->instanceNum); + hostIf_WiFi_Radio_Stats *pWifiRadioStats = hostIf_WiFi_Radio_Stats::getInstance(stMsgData->instanceNum); + + if ((!pWifiRadio) || (!pWifiRadioStats)) + { + return NOK; + } + + if (strcasecmp(pSetting,"Enable") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_Enable(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Status") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_Status(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Alias") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_Alias(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Name") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_Name(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"LastChange") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_LastChange(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"LowerLayers") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_LowerLayers(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Upstream") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_Upstream(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"MaxBitRate") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_MaxBitRate(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"SupportedFrequencyBands") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_SupportedFrequencyBands(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"OperatingFrequencyBand") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_OperatingFrequencyBand(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"SupportedStandards") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_SupportedStandards(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"OperatingStandards") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_OperatingStandards(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"PossibleChannels") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_PossibleChannels(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"ChannelsInUse") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_ChannelsInUse(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Channel") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_Channel(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"AutoChannelSupported") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_AutoChannelSupported(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"AutoChannelEnable") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_AutoChannelEnable(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"AutoChannelRefreshPeriod") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_AutoChannelRefreshPeriod(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"OperatingChannelBandwidth") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_OperatingChannelBandwidth(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"ExtensionChannel") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_ExtensionChannel(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"GuardInterval") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_GuardInterval(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"MCS") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_MCS(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"MCS") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_MCS(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"TransmitPowerSupported") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_TransmitPowerSupported(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"TransmitPower") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_TransmitPower(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"IEEE80211hSupported") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_IEEE80211hSupported(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"IEEE80211hEnabled") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_IEEE80211hEnabled(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"RegulatoryDomain") == 0) + { + ret = pWifiRadio->get_Device_WiFi_Radio_RegulatoryDomain(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.BytesSent") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_BytesSent(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.BytesReceived") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_BytesReceived(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.PacketsSent") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_PacketsSent(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.PacketsReceived") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_PacketsReceived(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.ErrorsSent") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_ErrorsSent(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.ErrorsReceived") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_ErrorsReceived(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.DiscardPacketsSent") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_DiscardPacketsSent(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.DiscardPacketsReceived") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_DiscardPacketsReceived(stMsgData,radioIndex); + } + else if (strcasecmp(pSetting,"Stats.Noise") == 0) + { + ret = pWifiRadioStats->get_Device_WiFi_Radio_Stats_NoiseFloor(stMsgData,radioIndex); + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d] Parameter : \'%s\' is Not Supported \n", __FUNCTION__, __LINE__, stMsgData->paramName); + stMsgData->faultCode = fcInvalidParameterName; + ret = NOK; + } + } + #endif else if (matchComponent(stMsgData->paramName, "Device.WiFi.Endpoint", &pSetting, instanceNum)) { stMsgData->instanceNum = instanceNum; @@ -557,6 +769,34 @@ void WiFiReqHandler::checkForUpdates() RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%s] hostIf_WiFi::getInstance(1) returned NULL\n", __FILE__, __FUNCTION__); return; } + #ifdef RDKV_TR69 + HOSTIF_MsgData_t stMsgData; + + if (OK == pIface->get_Device_WiFi_SSIDNumberOfEntries(&stMsgData)) + { + int currentSSIDNumberOfEntries = get_int (stMsgData.paramValue); + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s] currentSSIDNumberOfEntries = %d, savedSSIDNumberOfEntries = %d\n", + __FILE__, __FUNCTION__, currentSSIDNumberOfEntries, savedSSIDNumberOfEntries); + sendAddRemoveEvents (mUpdateCallback, currentSSIDNumberOfEntries, savedSSIDNumberOfEntries, (char *)DEVICE_WIFI_SSID_PROFILE); + } + + if (!bfirstInstance && (OK == pIface->get_Device_WiFi_RadioNumberOfEntries (&stMsgData))) + { + bfirstInstance = true; + int currentRadioNumberOfEntries = get_int (stMsgData.paramValue); + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s] currentRadioNumberOfEntries = %d, savedRadioNumberOfEntries = %d\n", + __FILE__, __FUNCTION__, currentRadioNumberOfEntries, savedRadioNumberOfEntries); + sendAddRemoveEvents (mUpdateCallback, currentRadioNumberOfEntries, savedRadioNumberOfEntries, (char *)DEVICE_WIFI_RADIO_PROFILE); + } + + if (OK == pIface->get_Device_WiFi_EndPointNumberOfEntries (&stMsgData)) + { + int currentEndPointNumberOfEntries = get_int (stMsgData.paramValue); + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s] currentEndPointNumberOfEntries = %d, savedEndPointNumberOfEntries = %d\n", + __FILE__, __FUNCTION__, currentEndPointNumberOfEntries, savedEndPointNumberOfEntries); + sendAddRemoveEvents (mUpdateCallback, currentEndPointNumberOfEntries, savedEndPointNumberOfEntries, (char *)DEVICE_WIFI_ENDPOINT_PROFILE); + } + #endif } #endif /* #ifdef USE_WIFI_PROFILE */ diff --git a/src/hostif/handlers/src/hostIf_XREClient_ReqHandler.cpp b/src/hostif/handlers/src/hostIf_XREClient_ReqHandler.cpp index e4add2545..3f67b39a4 100644 --- a/src/hostif/handlers/src/hostIf_XREClient_ReqHandler.cpp +++ b/src/hostif/handlers/src/hostIf_XREClient_ReqHandler.cpp @@ -45,6 +45,8 @@ updateCallback XREClientReqHandler::mUpdateCallback = NULL; GMutex XREClientReqHandler::m_mutex; int XREClientReqHandler::numOfEntries = 0; +#define XCONF_CHECKNOW_SCRIPT_CMD "backgroundrun /usr/bin/rdkvfwupgrader 0 3 >> /opt/logs/swupdate.log" + msgHandler* XREClientReqHandler::getInstance() { @@ -160,6 +162,17 @@ int XREClientReqHandler::handleSetMsg(HOSTIF_MsgData_t *stMsgData) { ret = set_Device_X_COMCAST_COM_Xcalibur_Client_XRE_xreLogLevel(stMsgData); } + #ifdef RDKV_TR69 + else if(strcasecmp(stMsgData->paramName,"Device.X_COMCAST-COM_Xcalibur.Client.XRE.xreReceiverRestart") == 0) + { + ret = setXreReceiverRestart(stMsgData); + } + else if(strcasecmp(stMsgData->paramName,"Device.X_COMCAST-COM_Xcalibur.DevApp.devAppRestartRequest") == 0) + { + // xreReceiverRestart uses /lib/rdk/restartReceiver.sh, which sometimes doesn't start receiver back + ret = setDevAppRestartRequest(stMsgData); + } + #endif else { stMsgData->faultCode = fcInvalidParameterName; @@ -199,6 +212,10 @@ int XREClientReqHandler::handleGetMsg(HOSTIF_MsgData_t *stMsgData) { ret = get_Device_X_COMCAST_COM_Xcalibur_Client_XRE_xreEnable(stMsgData); } + else if(strcasecmp(stMsgData->paramName,"Device.X_COMCAST-COM_Xcalibur.Client.xconfCheckNow") == 0) + { + ret = get_Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow(stMsgData); + } else if(strcasecmp(stMsgData->paramName,"Device.X_COMCAST-COM_Xcalibur.Client.XRE.xreStatus") == 0) { ret = get_Device_X_COMCAST_COM_Xcalibur_Client_XRE_xreStatus(stMsgData); @@ -469,6 +486,48 @@ void XREClientReqHandler::registerUpdateCallback(updateCallback cb) mUpdateCallback = cb; } +int set_Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow(HOSTIF_MsgData_t *stMsgData) +{ + FILE *file = fopen("/tmp/xconfchecknow_val", "w"); + if (file == NULL) { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF, "[%s:%s:%d]Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: Error opening file for write.\n",__FILE__,__FUNCTION__,__LINE__); + return NOK; + } + fprintf(file, "%s", stMsgData->paramValue); + fclose(file); + if(0 == strncasecmp("TRUE",stMsgData->paramValue ,strlen("TRUE")) || 0 == strncasecmp("CANARY",stMsgData->paramValue ,strlen("CANARY"))) + { + /*On setting xconfCheckNow,results the device to connect with the XCONF server + for the purpose of firmware and configuration checks.*/ + if(-1 == v_secure_system(XCONF_CHECKNOW_SCRIPT_CMD)) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF, "[%s:%s:%d]Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: Running checkNow script failed.\n",__FILE__,__FUNCTION__,__LINE__); + + return NOK; + } + + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF, "[%s:%s:%d]Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: CheckNow Running... \n",__FILE__,__FUNCTION__,__LINE__); + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF, "[%s:%s:%d]Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: \"%s\" Invalid Input. Valid Input is \"TRUE or CANARY\" \n",__FILE__,__FUNCTION__,__LINE__,stMsgData->paramValue); + return NOK; + } + return OK; +} + +int get_Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow(HOSTIF_MsgData_t *stMsgData) +{ + FILE *file = fopen("/tmp/xconfchecknow_val", "r"); + if (file == NULL) { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF, "[%s:%s:%d]Device_X_COMCAST_COM_Xcalibur_Client_xconfCheckNow: Error opening file for read.\n",__FILE__,__FUNCTION__,__LINE__); + return NOK; + } + fscanf(file, "%9s", stMsgData->paramValue); + fclose(file); + return OK; +} + void XREClientReqHandler::checkForUpdates() { HOSTIF_MsgData_t msgData; diff --git a/src/hostif/handlers/src/hostIf_dsClient_ReqHandler.cpp b/src/hostif/handlers/src/hostIf_dsClient_ReqHandler.cpp index d3db9e82f..3783b6549 100644 --- a/src/hostif/handlers/src/hostIf_dsClient_ReqHandler.cpp +++ b/src/hostif/handlers/src/hostIf_dsClient_ReqHandler.cpp @@ -82,15 +82,22 @@ bool DSClientReqHandler::init() { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s()] Device manager Initializing\n", __FUNCTION__); - try + while(true) { - device::Manager::Initialize(); + try + { + device::Manager::Initialize(); + } + catch(const std::exception &e) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Exception thrown while initializing device manager %s\n", e.what()); + sleep(3); + continue; + } + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s()] Device manager Initialized success break loop \n", __FUNCTION__); + break; } - catch(const std::exception &e) - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Exception thrown while initializing device manager %s\n", e.what()); - } - RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return true; } diff --git a/src/hostif/handlers/src/hostIf_jsonReqHandlerThread.cpp b/src/hostif/handlers/src/hostIf_jsonReqHandlerThread.cpp index 8ca599b7c..66eb2a43b 100644 --- a/src/hostif/handlers/src/hostIf_jsonReqHandlerThread.cpp +++ b/src/hostif/handlers/src/hostIf_jsonReqHandlerThread.cpp @@ -34,11 +34,7 @@ #include "hostIf_msgHandler.h" #include "hostIf_utils.h" #include -#ifdef LIBSOUP3_ENABLE #include "libsoup-3.0/libsoup/soup.h" -#else -#include "libsoup-2.4/libsoup/soup.h" -#endif #include #include extern T_ARGLIST argList; @@ -222,7 +218,6 @@ hostIf_HTTPJsonParse(const unsigned char *message, int length) return context.list; } -#ifdef LIBSOUP3_ENABLE void hostIf_HTTPJsonMsgHandler( SoupServer *server, SoupServerMessage *msg, @@ -338,123 +333,6 @@ void hostIf_HTTPJsonMsgHandler( RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return; } -#else -void hostIf_HTTPJsonMsgHandler( - SoupServer *server, - SoupMessage *msg, - const gchar *path, - GHashTable *query, - SoupClientContext *client, - gpointer user_data) -{ - GList *params; - - RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); - - if (!msg->request_body || - !msg->request_body->data || - !msg->request_body->length) - { - soup_message_set_status_full (msg, SOUP_STATUS_BAD_REQUEST, "No request data."); - RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting.. Failed due to no message data.\n", __FUNCTION__, __FILE__); - return; - } - - params = hostIf_HTTPJsonParse((const unsigned char *) msg->request_body->data, msg->request_body->length); - if (!params) - { - soup_message_set_status_full (msg, SOUP_STATUS_BAD_REQUEST, "No request data."); - RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting... Failed due to Parse HTTP Json messages. \n", __FUNCTION__, __FILE__); - return; - } - - yajl_gen json; -#ifndef YAJL_V2 - json = yajl_gen_alloc(/* &allocFuncs */ NULL, NULL); -#else - json = yajl_gen_alloc(NULL); -#endif - if (!json) - { - soup_message_set_status_full (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, "Cannot create return object"); - RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting.. Failed to create json object\n", __FUNCTION__, __FILE__); - return; - } - - yajl_gen_map_open(json); - yajl_gen_string(json, (const unsigned char *) "paramList", 9); - yajl_gen_array_open(json); - - GList *l = params; - while (l) - { - HOSTIF_MsgData_t *param = (HOSTIF_MsgData_t *) g_malloc0(sizeof(HOSTIF_MsgData_t)); - strncpy( param->paramName,(char *) l->data,TR69HOSTIFMGR_MAX_PARAM_LEN ); - // requestList = g_list_append(requestList, param); - - if (hostIf_GetMsgHandler(param) == OK) //We are expecting on Get call from JSON - { - yajl_gen_map_open(json); - yajl_gen_string(json, (const unsigned char *) "name", 4); - yajl_gen_string(json, (const unsigned char *) param->paramName, strlen(param->paramName)); - - yajl_gen_string(json, (const unsigned char *) "value", 5); - switch (param->paramtype) { - case hostIf_StringType: - yajl_gen_string(json, (const unsigned char*) param->paramValue, strlen((char*)param->paramValue)); - break; - case hostIf_IntegerType: - case hostIf_UnsignedIntType: - yajl_gen_integer(json, get_int(param->paramValue)); - break; - case hostIf_UnsignedLongType: - yajl_gen_integer(json, get_ulong(param->paramValue)); - break; - case hostIf_BooleanType: - yajl_gen_bool(json, get_boolean(param->paramValue)); - break; - case hostIf_DateTimeType: - // TODO: What to do here? What is the actual data representation? - yajl_gen_string(json, (const unsigned char *) "Unknown", 7); - break; - default: - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Unknown data type: %d", param->paramtype); - break; - } - - yajl_gen_map_close(json); - } - hostIf_Free_stMsgData(param); - - - l = l->next; - } - // Free the list, but do NOT deallocate the strings. They're now in the requestList - g_list_free_full(params, g_free); - params = NULL; - - // Close out the structures - yajl_gen_array_close(json); - yajl_gen_map_close(json); - - // Get the string - const unsigned char *buf; - unsigned int len; - yajl_gen_get_buf(json, &buf, &len); - - // TODO: What is the correct MIME type? - soup_message_set_response(msg, (const char *) "application/json", SOUP_MEMORY_COPY, (const char *) buf, len); - soup_message_set_status (msg, SOUP_STATUS_OK); - - yajl_gen_free(json); - - //json_t* incommingReq = NULL; - //json_t* outRes = NULL; - // ret = hostIf_JsonReqResHandler (incommingReq, outRes); - RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); - return; -} -#endif /** * @brief This API is used to initialize and start the HTTP server process. It use to serve the @@ -471,11 +349,7 @@ void hostIf_HttpServerStart() #endif if(server == NULL) -#ifdef LIBSOUP3_ENABLE server = soup_server_new("server-header", "hostif", NULL); -#else - server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "hostif", NULL); -#endif if (!server) { diff --git a/src/hostif/handlers/src/hostIf_msgHandler.cpp b/src/hostif/handlers/src/hostIf_msgHandler.cpp index 8e35c75f8..a73572299 100644 --- a/src/hostif/handlers/src/hostIf_msgHandler.cpp +++ b/src/hostif/handlers/src/hostIf_msgHandler.cpp @@ -30,6 +30,9 @@ **/ #include +#include +#include +#include #include "hostIf_main.h" #include "hostIf_msgHandler.h" #include "hostIf_utils.h" @@ -68,20 +71,143 @@ extern GHashTable* paramMgrhash; extern T_ARGLIST argList; static std::mutex get_handler_mutex; static std::mutex set_handler_mutex; +static int getCount = 0; +static int setCount = 0; +static std::atomic getCountSinceBoot{0}; +static time_t bootTimeSec = 0; +static std::atomic setCountSinceBoot{0}; +static time_t bootTimeSecSet =0; +static std::atomic loggedGet200Within1Min {false}; +static std::atomic loggedGet1000Within5Min {false}; +static std::atomic loggedSet200Within1Min {false}; +static std::atomic loggedSet1000Within5Min {false}; + +#define PARAM_VALUE_STR_SIZE 128 + + +void paramValueToString(const HOSTIF_MsgData_t *stMsgData, char *paramValueStr, size_t strSize) +{ + if (!stMsgData || !paramValueStr || strSize == 0) { + if (paramValueStr && strSize > 0) + snprintf(paramValueStr, strSize, ""); + return; + } + + switch (stMsgData->paramtype) { + case hostIf_StringType: + case hostIf_DateTimeType: + snprintf(paramValueStr, strSize, "%s", (const char*)stMsgData->paramValue); + break; + case hostIf_IntegerType: { + int val = 0; + memcpy(&val, stMsgData->paramValue, sizeof(val)); + snprintf(paramValueStr, strSize, "%d", val); + break; + } + case hostIf_UnsignedIntType: { + unsigned int val = 0; + memcpy(&val, stMsgData->paramValue, sizeof(val)); + snprintf(paramValueStr, strSize, "%u", val); + break; + } + case hostIf_BooleanType: { + bool val = false; + memcpy(&val, stMsgData->paramValue, sizeof(val)); + snprintf(paramValueStr, strSize, "%s", val ? "true" : "false"); + break; + } + case hostIf_UnsignedLongType: { + unsigned long val = 0; + memcpy(&val, stMsgData->paramValue, sizeof(val)); + snprintf(paramValueStr, strSize, "%lu", val); + break; + } + default: + snprintf(paramValueStr, strSize, ""); + break; + } +} int hostIf_GetMsgHandler(HOSTIF_MsgData_t *stMsgData) { LOG_ENTRY_EXIT; int ret = NOK; + getCount++; + if (getCount % 10 == 0) { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,"[%s:%d] GET called %d times\n",__FUNCTION__, __LINE__, getCount); + } std::lock_guard lock(get_handler_mutex); + // On first call, record boot time + if (bootTimeSec == 0) { + struct timespec ts; + clock_gettime(CLOCK_BOOTTIME, &ts); + bootTimeSec = ts.tv_sec; + } + getCountSinceBoot++; + + // Calculate seconds since boot + struct timespec now; + clock_gettime(CLOCK_BOOTTIME, &now); + long secondsSinceBoot = now.tv_sec - bootTimeSec; + + // Log if getCount reaches 200 before 1 minute from boot + if ( !loggedGet200Within1Min && getCountSinceBoot >= 200 && secondsSinceBoot <= 60) { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, + "[%s:%d] GET count reached 200 within 1 minute after boot (actual: %ld seconds)\n", + __FUNCTION__, __LINE__, secondsSinceBoot); + #ifdef T2_EVENT_ENABLED + t2CountNotify("TR69HOSTIF_GET_200_WITHIN_1MIN", 1); + #endif + loggedGet200Within1Min = true; + } + + // Log if getCount reaches 1000 before 5 minutes from boot + if ( !loggedGet1000Within5Min && getCountSinceBoot >= 1000 && secondsSinceBoot <= 300) { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, + "[%s:%d] GET count reached 1000 within 5 minutes after boot (actual: %ld seconds)\n", + __FUNCTION__, __LINE__, secondsSinceBoot); + #ifdef T2_EVENT_ENABLED + t2CountNotify("TR69HOSTIF_GET_1000_WITHIN_5MIN", 1); + #endif + loggedGet1000Within5Min =true; + } try { /* Find the respective manager and forward the request*/ msgHandler *pMsgHandler = HostIf_GetMgr(stMsgData); if(pMsgHandler) + { + auto startTime = std::chrono::high_resolution_clock::now(); ret = pMsgHandler->handleGetMsg(stMsgData); + auto endTime = std::chrono::high_resolution_clock::now(); + auto timeTaken = std::chrono::duration_cast(endTime - startTime).count(); + char paramValueStr[PARAM_VALUE_STR_SIZE] = {0}; + paramValueToString(stMsgData, paramValueStr, sizeof(paramValueStr)); + + + // Calculate time taken in microseconds + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, + "[%s:%d] ret: %d, paramName: %s, paramValue: %s, timeTaken: %lld us\n", + __FUNCTION__, __LINE__, ret, + stMsgData->paramName, + paramValueStr, + timeTaken); + // Telemetry and debug log if processing time > 5 second (1,000,000 us) + if (timeTaken > 5000000) { + // Debug log + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, + "[%s:%d] Slow GET detected: paramName: %s, timeTaken: %lld ms\n", + __FUNCTION__, __LINE__, stMsgData->paramName, timeTaken/1000); + #ifdef T2_EVENT_ENABLED + // Telemetry: report paramName + t2ValNotify("TR69HOSTIF_GET_TIMEOUT_PARAM", stMsgData->paramName); + #endif + + } + } + } catch (const std::exception& e) { @@ -94,15 +220,79 @@ int hostIf_GetMsgHandler(HOSTIF_MsgData_t *stMsgData) int hostIf_SetMsgHandler(HOSTIF_MsgData_t *stMsgData) { int ret = NOK; + setCount++; + if (setCount % 10 == 0) { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,"[%s:%d] SET called %d times\n",__FUNCTION__, __LINE__, setCount); + } std::lock_guard lock(set_handler_mutex); RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + if (bootTimeSecSet == 0) { + struct timespec ts; + clock_gettime(CLOCK_BOOTTIME, &ts); + bootTimeSecSet = ts.tv_sec; + } + setCountSinceBoot++; + + // Calculate seconds since boot for SET + struct timespec now; + clock_gettime(CLOCK_BOOTTIME, &now); + long secondsSinceBoot = now.tv_sec - bootTimeSecSet; + + // Log if setCount reaches 200 before 1 minute from boot + if (!loggedSet200Within1Min && setCountSinceBoot >= 200 && secondsSinceBoot <= 60) { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, + "[%s:%d] SET count reached 200 within 1 minute after boot (actual: %ld seconds)\n", + __FUNCTION__, __LINE__, secondsSinceBoot); + #ifdef T2_EVENT_ENABLED + t2CountNotify("TR69HOSTIF_SET_200_WITHIN_1MIN", 1); + #endif + loggedSet200Within1Min = true ; + } + + // Log if setCount reaches 1000 before 5 minutes from boot + if (!loggedSet1000Within5Min && setCountSinceBoot >= 1000 && secondsSinceBoot <= 300) { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, + "[%s:%d] SET count reached 1000 within 5 minutes after boot (actual: %ld seconds)\n", + __FUNCTION__, __LINE__, secondsSinceBoot); + #ifdef T2_EVENT_ENABLED + t2CountNotify("TR69HOSTIF_SET_1000_WITHIN_5MIN", 1); + #endif + loggedSet1000Within5Min = true; + } + + /* Find the respective manager and forward the request*/ msgHandler *pMsgHandler = HostIf_GetMgr(stMsgData); if(pMsgHandler) + { + auto startTime = std::chrono::high_resolution_clock::now(); ret = pMsgHandler->handleSetMsg(stMsgData); + auto endTime = std::chrono::high_resolution_clock::now(); + auto timeTakenset = std::chrono::duration_cast(endTime - startTime).count(); + + char paramValueStr[128] = {0}; + paramValueToString(stMsgData, paramValueStr, sizeof(paramValueStr)); + + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, + "[%s:%d] ret: %d, paramName: %s, paramValue: %s, timeTaken: %lld us\n", + __FUNCTION__, __LINE__, ret, + stMsgData->paramName, + paramValueStr, + timeTakenset); + // Telemetry and debug log if processing time > 5 seconds (5,000,000 us) + if (timeTakenset > 5000000) { + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, + "[%s:%d] Slow SET detected: paramName: %s, timeTaken: %lld ms\n", + __FUNCTION__, __LINE__, stMsgData->paramName, timeTakenset/1000); + #ifdef T2_EVENT_ENABLED + t2ValNotify("TR69HOSTIF_SET_TIMEOUT_PARAM", stMsgData->paramName); + #endif + + } + } RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return ret; diff --git a/src/hostif/handlers/src/hostIf_rbus_Dml_Provider.cpp b/src/hostif/handlers/src/hostIf_rbus_Dml_Provider.cpp index 0cdc2147f..314290852 100644 --- a/src/hostif/handlers/src/hostIf_rbus_Dml_Provider.cpp +++ b/src/hostif/handlers/src/hostIf_rbus_Dml_Provider.cpp @@ -514,7 +514,7 @@ void init_rbus_dml_provider() DataModelParam dmParam = {0}; if (getParamInfoFromDataModel(dataBaseHandle, dataElements[rbus_param_counter].name, &dmParam) == 0) { - RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s][rbusdml] Parameter not found. \n ", __FUNCTION__); + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s][rbusdml] Parameter not found: %s\n", __FUNCTION__, dataElements[rbus_param_counter].name); } else { @@ -633,3 +633,10 @@ int getRbusStringParam(const char *rbusParamName, char **rbusParamValue) { return OK ; } + +#ifdef GTEST_ENABLE +int (*convertRbus2hostIfDataTypeFunc()) (rbusValueType_t type, HostIf_ParamType_t* pParamType) +{ + return &convertRbus2hostIfDataType; +} +#endif diff --git a/src/hostif/httpserver/Makefile.am b/src/hostif/httpserver/Makefile.am index 2fe67f71a..2e8769a34 100644 --- a/src/hostif/httpserver/Makefile.am +++ b/src/hostif/httpserver/Makefile.am @@ -21,12 +21,8 @@ noinst_LTLIBRARIES=libhttpserver.la libhttpserver_la_SOURCES=src/http_server.cpp src/request_handler.cpp src/XrdkCentralComRFCVar.cpp -libhttpserver_la_LDFLAGS = -lrdkloggers -lwdmp-c $(SOUP_LIBS) -lcjson -if LIBSOUP3_ENABLE -libhttpserver_la_LDFLAGS += -lsoup-3.0 -else -libhttpserver_la_LDFLAGS += -lsoup-2.4 -endif +libhttpserver_la_LDFLAGS = -lrdkloggers -lwdmp-c $(SOUP_LIBS) -lcjson -lsoup-3.0 + AM_CXXFLAGS = "-std=c++11" $(SOUP_CFLAGS) -I$(top_srcdir)/src/hostif/httpserver/include \ -I$(top_srcdir)/src/hostif/include \ @@ -37,13 +33,10 @@ AM_CXXFLAGS = "-std=c++11" $(SOUP_CFLAGS) -I$(top_srcdir)/src/hostif/httpserver/ -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/glib-2.0 \ -I${PKG_CONFIG_SYSROOT_DIR}$(libdir)/glib-2.0/include \ -I$(top_srcdir)/src/hostif/parodusClient/waldb \ - -I$(top_srcdir)/src/hostif/parodusClient/pal + -I$(top_srcdir)/src/hostif/parodusClient/pal \ + -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/libsoup-3.0 + -if LIBSOUP3_ENABLE -AM_CXXFLAGS += -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/libsoup-3.0 -DLIBSOUP3_ENABLE -else -AM_CXXFLAGS += -I$(PKG_CONFIG_SYSROOT_DIR)/usr/include/libsoup-2.4 -endif libhttpserver_la_LIBADD = $(top_builddir)/src/hostif/parodusClient/waldb/libwaldb.la \ $(top_builddir)/src/hostif/handlers/libMsgHandlers.la diff --git a/src/hostif/httpserver/include/XrdkCentralComRFCVar.h b/src/hostif/httpserver/include/XrdkCentralComRFCVar.h index 590ba90a8..6143bc9e4 100644 --- a/src/hostif/httpserver/include/XrdkCentralComRFCVar.h +++ b/src/hostif/httpserver/include/XrdkCentralComRFCVar.h @@ -23,6 +23,10 @@ #include #include +#if defined(GTEST_ENABLE) +#include +#endif + using namespace std; #define XRFC_VAR_STORE_RELOADCACHE "RFC_CONTROL_RELOADCACHE" @@ -49,6 +53,11 @@ class XRFCVarStore void initRFCVarFileName(); bool loadRFCVarIntoCache(); +#if defined(GTEST_ENABLE) + FRIEND_TEST(httpserverTest, initRFCVarFileName); + FRIEND_TEST(httpserverTest, loadRFCVarIntoCache); + FRIEND_TEST(httpserverTest, Invalid_RFC_filename); +#endif }; #endif // XRDKCENTRALCOMRFCVARSTORE_H diff --git a/src/hostif/httpserver/include/request_handler.h b/src/hostif/httpserver/include/request_handler.h index 9b8814433..657e94b9e 100644 --- a/src/hostif/httpserver/include/request_handler.h +++ b/src/hostif/httpserver/include/request_handler.h @@ -65,7 +65,7 @@ #include "waldb.h" -#define MAX_PARAMETER_LEN 512 +#define MAX_PARAMETER_LEN 512 #define MAX_PARAMETERNAME_LEN 256 #ifdef __cplusplus diff --git a/src/hostif/httpserver/src/gtest/Makefile.am b/src/hostif/httpserver/src/gtest/Makefile.am new file mode 100644 index 000000000..54c1abfc8 --- /dev/null +++ b/src/hostif/httpserver/src/gtest/Makefile.am @@ -0,0 +1,37 @@ +################################################################################ +# Copyright 2024 Comcast Cable Communications Management, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +AUTOMAKE_OPTIONS = subdir-objects +# Define the program name and the source files +bin_PROGRAMS = httpserver_gtest + +# Define the include directories +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -DUSE_DEV_PROPERTIES_CONF -DUSE_REMOTE_DEBUGGER -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I$(TOP_DIR)/src/hostif/handlers/include -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/hostif/httpserver/include -I$(TOP_DIR)/src/hostif/handlers/src -I/usr/include/rbus -I/usr/local/include/rbus -Isrc/unittest/stubs/rbus/include/ -I$(TOP_DIR)/src/hostif/profiles/Time -I$(TOP_DIR)/src/hostif/profiles/Device -I$(TOP_DIR)/src/hostif/profiles/IP -I$(TOP_DIR)/src/hostif/profiles/STBService -I/usr/rdk-halif-device_settings/include/ -I/usr/rdkvhal-devicesettings-raspberrypi4/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$(TOP_DIR)/src/hostif/profiles/Ethernet -I/usr/remote_debugger/src/ -I/usr/local/include/libparodus/ -I/usr/local/include/wrp-c/ -I$(TOP_DIR)/src/hostif/parodusClient/startParodus/ -I/usr/include/libsoup-3.0 + +# Define the libraries to link against +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lglib-2.0 -llibparodus -lwrp-c -lnanomsg -lmsgpackc -ltrower-base64 -lcimplog -lgio-2.0 -lsoup-3.0 + +# Define the compiler flags +COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) $(SOUP_LIBS) -fprofile-arcs -ftest-coverage + +httpserver_gtest_SOURCES = $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_NotificationHandler.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_notification.cpp $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/unittest/stubs/wdmp-c.c $(TOP_DIR)/src/unittest/stubs/wdmp_internal.c $(TOP_DIR)/src/hostif/httpserver/src/http_server.cpp $(TOP_DIR)/src/hostif/httpserver/src/request_handler.cpp $(TOP_DIR)/src/hostif/httpserver/src/XrdkCentralComRFCVar.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_attribute.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_parameter.cpp $(TOP_DIR)/src/unittest/stubs/file_writer.cpp $(TOP_DIR)/src/hostif/httpserver/src/gtest/gtest_httpserver.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/libpd.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_adapter.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_msgHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_XrdkCentralT2_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_DeviceClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus_Process.cpp $(TOP_DIR)/src/hostif/profiles/Ethernet/Device_Ethernet_Interface.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_DisplayDevice.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_EthernetClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_TimeClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface.cpp $(TOP_DIR)/src/hostif/profiles/Time/Device_Time.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_updateHandler.cpp $(TOP_DIR)/src/hostif/profiles/Device/x_rdk_profile.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_dsClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_rbus_Dml_Provider.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Capabilities.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_SPDIF.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_VideoDecoder.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_AudioOutput.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_HDMI.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_VideoOutput.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface_Stats.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_ActivePort.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Diagnostics_IPPing.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface_IPv4Address.cpp $(TOP_DIR)/src/hostif/handlers/src/x_rdk_req_handler.cpp $(TOP_DIR)/src/unittest/stubs/ds/libprocps.cpp + +# Apply common properties to each program +httpserver_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) +httpserver_gtest_CXXFLAGS = $(COMMON_CXXFLAGS) +httpserver_gtest_LDADD = $(COMMON_LDADD) diff --git a/src/hostif/httpserver/src/gtest/gtest_httpserver.cpp b/src/hostif/httpserver/src/gtest/gtest_httpserver.cpp new file mode 100644 index 000000000..20993fdd7 --- /dev/null +++ b/src/hostif/httpserver/src/gtest/gtest_httpserver.cpp @@ -0,0 +1,726 @@ +#include +#include +#include +#include "hostIf_tr69ReqHandler.h" +#include "hostIf_utils.h" +#include "XrdkCentralComRFCStore.h" +#include "XrdkCentralComBSStore.h" +#include "XrdkCentralComBSStoreJournal.h" +#include "Device_DeviceInfo_Processor.h" +#include "Device_DeviceInfo_ProcessStatus.h" +#include "XrdkCentralComRFCVar.h" +#include "request_handler.h" +#include "IniFile.h" +#include "hostIf_utils.h" +#include "hostIf_main.h" +#include "webpa_notification.h" +#include "webpa_parameter.h" +#include "rbus_value.h" +#include "libsoup/soup.h" +#include +#include + +#include "rdk_debug.h" +#include "waldb.h" +#include "file_writer.h" + +#ifdef __cplusplus +extern "C" +{ +#endif +#include +#include +#ifdef __cplusplus +} +#endif + +#include "Device_DeviceInfo.h" + +#include +#include "cJSON.h" + +#include +#include + +#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/" +#define GTEST_DEFAULT_RESULT_FILENAME "hostif_gtest_report.json" +#define GTEST_REPORT_FILEPATH_SIZE 128 + +using namespace std; + +XRFCStore* m_rfcStore; +XBSStore* m_bsStore; +XBSStoreJournal* m_bsStoreJournal; +XRFCVarStore* m_varStore; + +extern GHashTable* paramMgrhash; + +std::mutex mtx_httpServerThreadDone; +std::condition_variable cv_httpServerThreadDone; +bool httpServerThreadDone = false; +GThread *HTTPServerThread = NULL; +char *HTTPServerName = (char *)"HTTPServerThread"; +GError *httpError = NULL; +GHashTable* paramMgrhash = NULL; +T_ARGLIST argList = {{'\0'}, 0}; +static SoupServer *http_server = NULL; + + +#ifdef GTEST_ENABLE +extern DATA_TYPE (*getWdmpDataTypeFunc())(char * ); +extern HostIf_ParamType_t (*getHostIfParamTypeFunc())(DATA_TYPE wdmpDataType); +bool (*validateParamValueFunc())(const string ¶mValue, HostIf_ParamType_t dataType); +WDMP_STATUS (*handleRFCRequestFunc())(REQ_TYPE reqType, param_t *param); +WDMP_STATUS (*invokeHostIfAPIFunc())(REQ_TYPE reqType, param_t *param, HostIf_Source_Type_t bsUpdate, const char *pcCallerID); +WDMP_STATUS (*validateAgainstDataModelFunc())(REQ_TYPE reqType, char* paramName, const char* paramValue, DATA_TYPE *dataType, char **defaultValue, HostIf_Source_Type_t *bsUpdate); +extern void (*HTTPRequestHandlerFunc()) ( + SoupServer *server, + SoupServerMessage *msg, + const char *path, + GHashTable *query, + void *user_data); +extern void (*convertAndAssignParamValueFunc()) (HOSTIF_MsgData_t *param, char *value); +extern char* (*getStringValueFunc()) (HostIf_ParamType_t paramType, char *value); +#endif + +TEST(httpserverTest,initRFCVarFileName){ + m_varStore=XRFCVarStore::getInstance(); + if(m_varStore) + { + m_varStore->initRFCVarFileName(); + m_varStore->m_filename.erase(std::remove(m_varStore->m_filename.begin(),m_varStore->m_filename.end(),'"'),m_varStore->m_filename.end()); + EXPECT_EQ(m_varStore->m_filename,"/opt/secure/RFC/rfcVariable.ini"); + } +} + +TEST(httpserverTest, loadRFCVarIntoCache) { + m_varStore = XRFCVarStore::getInstance(); + if(m_varStore) + { + bool ret = m_varStore->loadRFCVarIntoCache(); + EXPECT_EQ(ret, true); + } +} + +TEST(httpserverTest, getValue) { + m_varStore = XRFCVarStore::getInstance(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.WebCfgData"; + if(m_varStore) + { + string value = m_varStore->getValue(key); + EXPECT_EQ(value, "testCfg"); + } +} + + +TEST(httpserverTest, getWdmpDataType) { + EXPECT_EQ(getWdmpDataTypeFunc()("string"), WDMP_STRING); + EXPECT_EQ(getWdmpDataTypeFunc()("boolean"), WDMP_BOOLEAN); + EXPECT_EQ(getWdmpDataTypeFunc()("unsignedInt"), WDMP_UINT); + EXPECT_EQ(getWdmpDataTypeFunc()("int"), WDMP_INT); + EXPECT_EQ(getWdmpDataTypeFunc()("unsignedLong"), WDMP_ULONG); + EXPECT_EQ(getWdmpDataTypeFunc()("dataTime"), WDMP_DATETIME); + EXPECT_EQ(getWdmpDataTypeFunc()("float"), WDMP_NONE); +} + +TEST(httpserverTest, getHostIfParamType) { + EXPECT_EQ(getHostIfParamTypeFunc()(WDMP_STRING), hostIf_StringType); + EXPECT_EQ(getHostIfParamTypeFunc()(WDMP_INT), hostIf_IntegerType); + EXPECT_EQ(getHostIfParamTypeFunc()(WDMP_UINT), hostIf_UnsignedIntType); + EXPECT_EQ(getHostIfParamTypeFunc()(WDMP_BOOLEAN), hostIf_BooleanType); + EXPECT_EQ(getHostIfParamTypeFunc()(WDMP_DATETIME), hostIf_DateTimeType); + EXPECT_EQ(getHostIfParamTypeFunc()(WDMP_BASE64), hostIf_StringType); +} + +TEST(httpserverTest, validateParamValue) { + const string sparamValue = "testimage"; + HostIf_ParamType_t dataType = hostIf_StringType; + EXPECT_EQ(validateParamValueFunc()(sparamValue, dataType), true); + + const string bparamValue = "0"; + dataType = hostIf_BooleanType; + EXPECT_EQ(validateParamValueFunc()(bparamValue, dataType), true); + + const string iparamValue = "12800"; + dataType = hostIf_IntegerType; + EXPECT_EQ(validateParamValueFunc()(iparamValue, dataType), true); + + const string uiparamValue = "12"; + dataType = hostIf_UnsignedIntType; + EXPECT_EQ(validateParamValueFunc()(uiparamValue, dataType), true); + + const string paramValue = "flase"; + dataType = hostIf_BooleanType; + EXPECT_EQ(validateParamValueFunc()(paramValue, dataType), false); + + const string invalidIntValue = "123abc"; + dataType = hostIf_IntegerType; + EXPECT_EQ(validateParamValueFunc()(invalidIntValue, dataType), false); + + const string invalidLongValue = "123dab"; + dataType = hostIf_UnsignedLongType; + EXPECT_EQ(validateParamValueFunc()(invalidLongValue, dataType), false); +} + +TEST(httpserverTest, handleRFCRequest_GET) { + param_t param; + memset(¶m,0,sizeof(param_t)); + param.name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType"); + + REQ_TYPE reqType = GET; + WDMP_STATUS status = handleRFCRequestFunc()(reqType, ¶m); + EXPECT_EQ(status, WDMP_SUCCESS); + + EXPECT_STREQ(param.value, "testtype"); + free(param.name); +} + +TEST(httpserverTest, handleRFCRequest_SET) { + param_t param; + memset(¶m,0,sizeof(param_t)); + param.name = strdup(XRFC_VAR_STORE_RELOADCACHE); + param.value = strdup("true"); + + REQ_TYPE reqType = SET; + WDMP_STATUS status = handleRFCRequestFunc()(reqType, ¶m); + EXPECT_EQ(status, WDMP_SUCCESS); + free(param.name); + free(param.value); +} + +TEST(httpserverTest, InvalidReqtype) { + param_t param; + memset(¶m,0,sizeof(param_t)); + param.name = strdup(XRFC_VAR_STORE_RELOADCACHE); + param.value = strdup("true"); + + REQ_TYPE reqType = DELETE_ROW; + WDMP_STATUS status = handleRFCRequestFunc()(reqType, ¶m); + EXPECT_EQ(status, WDMP_SUCCESS); + free(param.name); + free(param.value); +} + +TEST(httpserverTest, handleRFCInvalidRequest) { + param_t param; + memset(¶m,0,sizeof(param_t)); + param.name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.Control.ClearDB"); + param.value = strdup("true"); + + REQ_TYPE reqType = SET; + WDMP_STATUS status = handleRFCRequestFunc()(reqType, ¶m); + EXPECT_EQ(status, WDMP_ERR_METHOD_NOT_SUPPORTED); + free(param.name); + free(param.value); +} + +TEST(httpserverTest, invokeHostIfAPI_SET_FAILURE) { + param_t param; + memset(¶m,0,sizeof(param_t)); + param.name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable"); + param.value = strdup("true"); + + const char *pcCallerID = "rfc"; + + HOSTIF_MsgData_t msgData = { 0 }; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.bsUpdate = HOSTIF_NONE; + + REQ_TYPE reqType = SET; + WDMP_STATUS status = invokeHostIfAPIFunc()(reqType, ¶m, msgData.bsUpdate, pcCallerID); + EXPECT_EQ(status, 37); +} + + +TEST(httpserverTest, invokeHostIfAPI) { + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + param_t param; + memset(¶m,0,sizeof(param_t)); + param.name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable"); + writeToTr181storeFile("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable", "true", "/opt/secure/RFC/tr181store.ini", Plain); + const char *pcCallerID = "rfc"; + + HOSTIF_MsgData_t msgData = { 0 }; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.bsUpdate = HOSTIF_NONE; + + REQ_TYPE reqType = GET; + WDMP_STATUS status = invokeHostIfAPIFunc()(reqType, ¶m, msgData.bsUpdate, pcCallerID); + EXPECT_EQ(status, WDMP_SUCCESS); + +} + +TEST(httpserverTest, invokeHostIfAPI_SET) { + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + param_t param; + memset(¶m,0,sizeof(param_t)); + param.name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.SsrUrl"); + param.value = strdup("https://ssr.ccp.xcal.tv"); + + const char *pcCallerID = "rfc"; + + HOSTIF_MsgData_t msgData = { 0 }; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.bsUpdate = HOSTIF_NONE; + + REQ_TYPE reqType = SET; + WDMP_STATUS status = invokeHostIfAPIFunc()(reqType, ¶m, msgData.bsUpdate, pcCallerID); + EXPECT_EQ(status, WDMP_SUCCESS); +} + +TEST(httpserverTest, invokeHostIfAPI_InvalidReq) { + param_t param; + memset(¶m,0,sizeof(param_t)); + param.name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfUrl"); + const char *pcCallerID = "webpa"; + + HOSTIF_MsgData_t msgData = { 0 }; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.bsUpdate = HOSTIF_NONE; + + strncpy(msgData.paramValue, "https://ssr.ccp.xcal.tv", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + REQ_TYPE reqType = REPLACE_ROWS; + WDMP_STATUS status = invokeHostIfAPIFunc()(reqType, ¶m, msgData.bsUpdate, pcCallerID); + EXPECT_EQ(status, WDMP_ERR_INTERNAL_ERROR); +} + +TEST(httpserverTest, validateAgainstDataModel_GET) { + + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + HOSTIF_MsgData_t msgData = { 0 }; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.bsUpdate = HOSTIF_NONE; + + char paramName [] = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.Enable"; + const char* paramValue = NULL; + DATA_TYPE dataType = WDMP_BOOLEAN; + + REQ_TYPE reqType = GET; + char defaultValue[66]; + char* defaultValuePtr = defaultValue; + WDMP_STATUS status = validateAgainstDataModelFunc()(reqType, paramName, paramValue, &dataType, &defaultValuePtr, &msgData.bsUpdate); + EXPECT_EQ(status, WDMP_SUCCESS); + EXPECT_STREQ(defaultValuePtr, "false"); + +} + +TEST(httpserverTest, validateAgainstDataModel_SET_NullParam) { + + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + HOSTIF_MsgData_t msgData = { 0 }; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.bsUpdate = HOSTIF_NONE; + + char paramName [] = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName"; + const char* paramValue = NULL; + DATA_TYPE dataType = WDMP_BOOLEAN; + + REQ_TYPE reqType = SET; + char defaultValue[66]; + char* defaultValuePtr = defaultValue; + WDMP_STATUS status = validateAgainstDataModelFunc()(SET, paramName, paramValue, &dataType, &defaultValuePtr, &msgData.bsUpdate); + EXPECT_EQ(status, WDMP_ERR_VALUE_IS_NULL); +} + +TEST(httpserverTest, validateAgainstDataModel_SET_ReadOnly) { + + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + HOSTIF_MsgData_t msgData = { 0 }; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.bsUpdate = HOSTIF_NONE; + + char paramName [] = "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ReverseSSH.xOpsReverseSshStatus"; + const char* paramValue = "reverseSsh"; + DATA_TYPE dataType = WDMP_BOOLEAN; + + REQ_TYPE reqType = SET; + char defaultValue[66]; + char* defaultValuePtr = defaultValue; + WDMP_STATUS status = validateAgainstDataModelFunc()(SET, paramName, paramValue, &dataType, &defaultValuePtr, &msgData.bsUpdate); + EXPECT_EQ(status, WDMP_ERR_NOT_WRITABLE); +} + +TEST(httpserverTest, validateAgainstDataModel_INVALID_PARAMETER_NAME) { + + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + HOSTIF_MsgData_t msgData = { 0 }; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.bsUpdate = HOSTIF_NONE; + + char paramName [] = "Device.DeviceInfoTest.FriendlyName"; + const char* paramValue = "reverseSsh"; + DATA_TYPE dataType = WDMP_BOOLEAN; + + REQ_TYPE reqType = SET; + char defaultValue[66]; + char* defaultValuePtr = defaultValue; + WDMP_STATUS status = validateAgainstDataModelFunc()(SET, paramName, paramValue, &dataType, &defaultValuePtr, &msgData.bsUpdate); + EXPECT_EQ(status, WDMP_ERR_INVALID_PARAMETER_NAME); +} + +TEST(httpserverTest, handleRequest_GET) { + + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + const char* pcCallerID = "rfc"; + get_req_t *getReq = (get_req_t *)malloc(sizeof(get_req_t)); + getReq->paramCnt = 1; + getReq->paramNames[0] = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable"); + //getReq->paramNames[1] = strdup("Device.DeviceInfo."); + req_struct reqSt; + reqSt.reqType = GET; // Replace with actual enum value if it's defined + reqSt.u.getReq = getReq; + + + res_struct* respSt = handleRequest(pcCallerID, &reqSt); + EXPECT_EQ(respSt->retStatus[0], WDMP_ERR_DEFAULT_VALUE); +} + +TEST(httpserverTest, handlewildRequest_GET) { + + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + const char* pcCallerID = "rfc"; + get_req_t *getReq = (get_req_t *)malloc(sizeof(get_req_t)); + getReq->paramCnt = 1; + getReq->paramNames[0] = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary."); + //getReq->paramNames[1] = strdup("Device.DeviceInfo."); + req_struct reqSt; + reqSt.reqType = GET; // Replace with actual enum value if it's defined + reqSt.u.getReq = getReq; + + + res_struct* respSt = handleRequest(pcCallerID, &reqSt); + //EXPECT_EQ(respSt->retStatus[0], WDMP_ERR_DEFAULT_VALUE); + EXPECT_EQ(respSt->retStatus[0], 0); + +} + +TEST(httpserverTest, handlewildRequestINVALIDPARAM_GET) { + + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + const char* pcCallerID = "rfc"; + get_req_t *getReq = (get_req_t *)malloc(sizeof(get_req_t)); + getReq->paramCnt = 1; + getReq->paramNames[0] = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.SystemServices.FriendlyName"); + req_struct reqSt; + reqSt.reqType = GET; // Replace with actual enum value if it's defined + reqSt.u.getReq = getReq; + + + res_struct* respSt = handleRequest(pcCallerID, &reqSt); + EXPECT_EQ(respSt->retStatus[0], 22); +} + +/* TEST(httpserverTest, paramCount_GET) { + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + const char* pcCallerID = "rfc"; + get_req_t *getReq = (get_req_t *)malloc(sizeof(get_req_t)); + getReq->paramCnt = 0; + // getReq->paramNames[0] = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.SystemServices.FriendlyName"); + req_struct reqSt; + reqSt.reqType = GET; // Replace with actual enum value if it's defined + reqSt.u.getReq = getReq; + + + res_struct* respSt = handleRequest(pcCallerID, &reqSt); + EXPECT_EQ(respSt->retStatus[0], NULL); +} + + +TEST(httpserverTest, paramCount_SET) { + + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + const char* pcCallerID = "rfc"; + get_req_t *getReq = (get_req_t *)malloc(sizeof(get_req_t)); + getReq->paramCnt = 0; + // getReq->paramNames[0] = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.SystemServices.FriendlyName"); + req_struct reqSt; + reqSt.reqType = SET; // Replace with actual enum value if it's defined + reqSt.u.getReq = getReq; + + + res_struct* respSt = handleRequest(pcCallerID, &reqSt); + EXPECT_EQ(respSt->retStatus[0], NULL); +} +*/ + +/* TEST(httpserverTest, paramCount_InvalidParamName) { + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + const char* pcCallerID = "rfc"; + get_req_t *getReq = (get_req_t *)malloc(sizeof(get_req_t)); + getReq->paramCnt = 1; + getReq->paramNames[0] = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable.Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable.Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable.Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable.Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable"); + req_struct reqSt; + reqSt.reqType = SET; // Replace with actual enum value if it's defined + reqSt.u.getReq = getReq; + + + res_struct* respSt = handleRequest(pcCallerID, &reqSt); + EXPECT_EQ(respSt->retStatus[0], WDMP_ERR_INVALID_PARAMETER_NAME); +} */ + +TEST(httpserverTest, handleRequest_SET) { + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + const char* pcCallerID = "rfc"; + + param_t *params = (param_t *) malloc(sizeof(param_t) * 3); + params[0].name = strdup("Device.X_CISCO_COM_DeviceControl.RebootDevice"); + params[0].value = strdup("true"); + params[0].type = WDMP_BOOLEAN; + + params[1].name = strdup("Device.DeviceInfo."); + params[1].value = strdup("true"); + params[1].type = WDMP_BOOLEAN; + + params[2].name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable"); + params[2].value = NULL; + params[2].type = WDMP_BOOLEAN; + + set_req_t *setReq = (set_req_t *)malloc(sizeof(set_req_t)); + setReq->param = params; + setReq->paramCnt = 3; + + req_struct reqSt; + reqSt.reqType = SET; // Replace with actual enum value + reqSt.u.setReq = setReq; + + res_struct* respSt = handleRequest(pcCallerID, &reqSt); + EXPECT_EQ(respSt->retStatus[0], WDMP_FAILURE); + EXPECT_EQ(respSt->retStatus[1], WDMP_ERR_WILDCARD_NOT_SUPPORTED); + EXPECT_EQ(respSt->retStatus[2], WDMP_ERR_VALUE_IS_NULL); +} + + +TEST(httpserverTest, convertAndAssignParamValue_BooleanType) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + convertAndAssignParamValueFunc()(¶m, "true"); + EXPECT_EQ(0, 0); +} + +TEST(httpserverTest, convertAndAssignParamValue_StringType) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + convertAndAssignParamValueFunc()(¶m, "Testtype"); + EXPECT_EQ(0, 0); +} + +TEST(httpserverTest, convertAndAssignParamValue_IntegerType) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + param.paramtype = hostIf_IntegerType; + param.paramLen = sizeof(hostIf_IntegerType); + + convertAndAssignParamValueFunc()(¶m, "1180000"); + EXPECT_EQ(0, 0); +} + +TEST(httpserverTest, convertAndAssignParamValue_UnsignedLongType) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.Ethernet.Interface.1.Stats.BytesReceived", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + param.paramtype = hostIf_UnsignedLongType; + param.paramLen = sizeof(hostIf_UnsignedLongType); + + convertAndAssignParamValueFunc()(¶m, "123456789"); + EXPECT_EQ(0, 0); +} + +TEST(httpserverTest, getStringValue) { + EXPECT_STREQ(getStringValueFunc()(hostIf_StringType, "global"), "global"); + EXPECT_STREQ(getStringValueFunc()(hostIf_IntegerType, "100"), "3158065"); + EXPECT_STREQ(getStringValueFunc()(hostIf_BooleanType, "true"), "false"); + EXPECT_STREQ(getStringValueFunc()(hostIf_BooleanType, "false"), "false"); + EXPECT_STREQ(getStringValueFunc()(hostIf_UnsignedLongType, "123456789"), "4050765991979987505"); +} + +TEST(httpserverTest, Invalid_RFC_filename) { + m_varStore = XRFCVarStore::getInstance(); + m_varStore->m_filename = "/opt/secure/RFC1/rfctest_Variable.ini"; + std::ofstream file("/opt/secure/RFC1/rfctest_Variable.ini"); + file.close(); + if(m_varStore) + { + bool ret = m_varStore->loadRFCVarIntoCache(); + EXPECT_EQ(ret, false); + } +} + +TEST(httpserverTest, HTTPRequestHandler_GET) { + + // Create a SoupMessage for POST + SoupServer *server = soup_server_new(nullptr, nullptr); + SoupMessage *msg = soup_message_new("POST", "http://localhost/api/status"); + const char *json_body = "{\"action\":\"ping\"}"; + GBytes *body_bytes = g_bytes_new_static(json_body, strlen(json_body)); + soup_message_set_request_body_from_bytes(msg, "application/json", body_bytes); + SoupMessageHeaders *headers = soup_message_get_request_headers(msg); + soup_message_headers_append(headers, "CallerID", "unittest"); + + HTTPRequestHandlerFunc()(server, reinterpret_cast(msg), "/api/status", nullptr, nullptr); + EXPECT_EQ(0, 0); +} + + +GTEST_API_ int main(int argc, char *argv[]){ + char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE]; + char buffer[GTEST_REPORT_FILEPATH_SIZE]; + + memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE ); + memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE ); + snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME); + + ::testing::GTEST_FLAG(output) = testresults_fullfilepath; + ::testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/hostif/httpserver/src/http_server.cpp b/src/hostif/httpserver/src/http_server.cpp index 47479fbb5..d7ae0c1e1 100644 --- a/src/hostif/httpserver/src/http_server.cpp +++ b/src/hostif/httpserver/src/http_server.cpp @@ -48,7 +48,7 @@ extern bool httpServerThreadDone; extern T_ARGLIST argList; static SoupServer *http_server = NULL; -#ifdef LIBSOUP3_ENABLE + static void HTTPRequestHandler( SoupServer *server, SoupServerMessage *msg, @@ -220,177 +220,7 @@ static void HTTPRequestHandler( RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return; } -#else -static void HTTPRequestHandler( - SoupServer *server, - SoupMessage *msg, - const char *path, - GHashTable *query, - SoupClientContext *client, - void *user_data) -{ - cJSON *jsonRequest = NULL; - cJSON *jsonResponse = NULL; - req_struct *reqSt = NULL; - res_struct *respSt = NULL; - - struct timespec start,end,*startPtr,*endPtr; - startPtr = &start; - endPtr = &end; - - RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); - getCurrentTime(startPtr); - if (!msg->request_body || - !msg->request_body->data || - !msg->request_body->length) - { - soup_message_set_status_full (msg, SOUP_STATUS_BAD_REQUEST, "No request data."); - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,"[%s:%s] Exiting.. Failed due to no message data.\n", __FUNCTION__, __FILE__); - return; - } - - const char *pcCallerID = (char *)soup_message_headers_get_one(msg->request_headers, "CallerID"); - - jsonRequest = cJSON_Parse((const char *) msg->request_body->data); - - if(jsonRequest) - { - reqSt = (req_struct *)malloc(sizeof(req_struct)); - if(reqSt == NULL) - { - soup_message_set_status_full (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, "Cannot create return object"); - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,"[%s:%s] Exiting.. Failed to create req_struct\n", __FUNCTION__, __FILE__); - return; - } - memset(reqSt, 0, sizeof(req_struct)); - - if(!strcmp(msg->method, "GET")) - { - if(!pcCallerID || !strlen(pcCallerID)) - { - pcCallerID = "Unknown"; - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%s] Unknown Caller ID, GET is allowed by default\n", __FUNCTION__, __FILE__); - } - else - RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF,"[%s:%s] GET with CallerID : %s..\n", __FUNCTION__, __FILE__, pcCallerID); - parse_get_request(jsonRequest, &reqSt, WDMP_TR181); - respSt = handleRequest(pcCallerID, reqSt); - if(respSt) - { - jsonResponse = cJSON_CreateObject(); - wdmp_form_get_response(respSt, jsonResponse); - - // WDMP Code sets a generic statusCode, the following lines replace it with an actual error code. - int new_st_code = 0; - - for(size_t paramIndex = 0; paramIndex < respSt->paramCnt; paramIndex++) - { - if(respSt->retStatus[paramIndex] != 0 || paramIndex == respSt->paramCnt-1) - { - new_st_code = respSt->retStatus[paramIndex]; - break; - } - } - cJSON * stcode = cJSON_GetObjectItem(jsonResponse, "statusCode"); - if( NULL != stcode) - { - cJSON_SetIntValue(stcode, new_st_code); - } - } - else - { - soup_message_set_status_full (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, "Invalid request format"); - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,"[%s:%s] Exiting.. Request couldn't be processed\n", __FUNCTION__, __FILE__); - return; - } - } - else if(!strcmp(msg->method, "POST")) - { - if(!pcCallerID || !strlen(pcCallerID)) - { - soup_message_set_status_full (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, "POST Not Allowed without CallerID"); - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,"[%s:%s] Exiting.. POST operation not allowed with unknown CallerID\n", __FUNCTION__, __FILE__); - wdmp_free_req_struct(reqSt); - reqSt = NULL; - return; - } - else - RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF,"[%s:%s] POST with CallerID : %s..\n", __FUNCTION__, __FILE__, pcCallerID); - parse_set_request(jsonRequest, &reqSt, WDMP_TR181); - RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF,"Calling handleRequest...\n"); - respSt = handleRequest(pcCallerID, reqSt); - if(respSt) - { - jsonResponse = cJSON_CreateObject(); - wdmp_form_set_response(respSt, jsonResponse); - // WDMP Code sets a generic statusCode, the following lines replace it with an actual error code. - int new_st_code = 0; - - for(size_t paramIndex = 0; paramIndex < respSt->paramCnt; paramIndex++) - { - if(respSt->retStatus[paramIndex] != 0 || paramIndex == respSt->paramCnt-1) - { - new_st_code = respSt->retStatus[paramIndex]; - break; - } - } - cJSON * stcode = cJSON_GetObjectItem(jsonResponse, "statusCode"); - if( NULL != stcode) - { - cJSON_SetIntValue(stcode, new_st_code); - } - } - else - { - soup_message_set_status_full (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, "Invalid request format"); - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,"[%s:%s] Exiting.. Request couldn't be processed\n", __FUNCTION__, __FILE__); - wdmp_free_req_struct(reqSt); - reqSt = NULL; - return; - } - } - else - { - soup_message_set_status_full (msg, SOUP_STATUS_NOT_IMPLEMENTED, "Method not implemented"); - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,"[%s:%s] Exiting.. Unsupported operation \n", __FUNCTION__, __FILE__); - wdmp_free_req_struct(reqSt); - reqSt = NULL; - return; - } - - char *buf = cJSON_Print(jsonResponse); - - if(buf) { - soup_message_set_response(msg, (const char *) "application/json", SOUP_MEMORY_COPY, buf, strlen(buf)); - soup_message_set_status (msg, SOUP_STATUS_OK); - } - - wdmp_free_req_struct(reqSt); - reqSt = NULL; - cJSON_Delete(jsonRequest); - cJSON_Delete(jsonResponse); - wdmp_free_res_struct(respSt); - respSt = NULL; - - if(buf != NULL) { - free(buf); - buf = NULL; - } - } - else - { - soup_message_set_status_full (msg, SOUP_STATUS_BAD_REQUEST, "Bad Request"); - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,"[%s:%s] Exiting.. Failed to parse JSON Message \n", __FUNCTION__, __FILE__); - return; - } - - getCurrentTime(endPtr); - RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Curl Request Processing Time : %lu ms\n", timeValDiff(startPtr, endPtr)); - RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); - return; -} -#endif void *HTTPServerStartThread(void *msg) { @@ -413,11 +243,7 @@ void *HTTPServerStartThread(void *msg) } if(http_server == NULL) -#ifdef LIBSOUP3_ENABLE http_server = soup_server_new("server-header", "HTTPServer", NULL); -#else - http_server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "HTTPServer", NULL); -#endif if (!http_server) { @@ -463,3 +289,15 @@ void HttpServerStop() RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF,"SERVER: Stopped server successfully.\n"); } } + +#ifdef GTEST_ENABLE +void (*HTTPRequestHandlerFunc()) ( + SoupServer *server, + SoupServerMessage *msg, + const char *path, + GHashTable *query, + void *user_data) +{ + return &HTTPRequestHandler; +} +#endif diff --git a/src/hostif/httpserver/src/request_handler.cpp b/src/hostif/httpserver/src/request_handler.cpp index 20cf518f8..a324f5f23 100644 --- a/src/hostif/httpserver/src/request_handler.cpp +++ b/src/hostif/httpserver/src/request_handler.cpp @@ -738,3 +738,46 @@ res_struct* handleRequest(const char* pcCallerID, req_struct *reqSt) RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Leaving... %s\n", __FUNCTION__); return respSt; } + +#ifdef GTEST_ENABLE +DATA_TYPE (*getWdmpDataTypeFunc())(char * ) +{ + return &getWdmpDataType; +} + +HostIf_ParamType_t (*getHostIfParamTypeFunc())(DATA_TYPE wdmpDataType) +{ + return &getHostIfParamType; +} + +bool (*validateParamValueFunc())(const string ¶mValue, HostIf_ParamType_t dataType) +{ + return &validateParamValue; +} + +WDMP_STATUS (*handleRFCRequestFunc())(REQ_TYPE reqType, param_t *param) +{ + return &handleRFCRequest; +} + +WDMP_STATUS (*invokeHostIfAPIFunc())(REQ_TYPE reqType, param_t *param, HostIf_Source_Type_t bsUpdate, const char *pcCallerID) +{ + return &invokeHostIfAPI; +} + +WDMP_STATUS (*validateAgainstDataModelFunc())(REQ_TYPE reqType, char* paramName, const char* paramValue, DATA_TYPE *dataType, char ** +defaultValue, HostIf_Source_Type_t *bsUpdate) +{ + return &validateAgainstDataModel; +} + +void (*convertAndAssignParamValueFunc()) (HOSTIF_MsgData_t *param, char *value) +{ + return &convertAndAssignParamValue; +} + +char* (*getStringValueFunc()) (HostIf_ParamType_t paramType, char *value) +{ + return &getStringValue; +} +#endif diff --git a/src/hostif/include/IniFile.h b/src/hostif/include/IniFile.h index 013a7cecc..1bff86c3c 100644 --- a/src/hostif/include/IniFile.h +++ b/src/hostif/include/IniFile.h @@ -23,6 +23,10 @@ #include #include +#if defined(GTEST_ENABLE) +#include +#endif + class IniFile { public: @@ -36,6 +40,10 @@ class IniFile private: std::string m_filename; std::map m_dict; + +#if defined(GTEST_ENABLE) + FRIEND_TEST(srcTest, flush); +#endif }; #endif /* INIFILE_H_ */ diff --git a/src/hostif/include/hostIf_main.h b/src/hostif/include/hostIf_main.h index 4b064fade..f99cb0195 100644 --- a/src/hostif/include/hostIf_main.h +++ b/src/hostif/include/hostIf_main.h @@ -109,22 +109,25 @@ #include #include "rdk_debug.h" -extern gchar *date_str; + +extern gchar *date_str; typedef enum { MERGE_SUCCESS, MERGE_FAILURE } MergeStatus; - - void tr69hostIf_logger (const gchar *log_domain, GLogLevelFlags log_level,const gchar *message, gpointer user_data); MergeStatus mergeDataModel(); bool filter_and_merge_xml(const char *input1, const char *input2, const char *output); +MergeStatus mergeDataModelRDKV(const char* rdk_profile); +MergeStatus mergeDataModelRDKE(const char* rdk_profile); #define G_LOG_DOMAIN ((gchar*) 0) #define LOG_TR69HOSTIF "LOG.RDK.TR69HOSTIF" + + using namespace std; enum { @@ -147,6 +150,8 @@ static volatile sig_atomic_t time_to_quit = 0; void quit_handler (int sig_received); void exit_gracefully (int sig_received); + + void *tr69IfHandlerThread(void *); void *jsonIfHandlerThread(void *); pid_t getTid(); diff --git a/src/hostif/include/hostIf_utils.h b/src/hostif/include/hostIf_utils.h index 2e2e5c1c8..179aa5760 100755 --- a/src/hostif/include/hostIf_utils.h +++ b/src/hostif/include/hostIf_utils.h @@ -54,6 +54,16 @@ #define BUFF_LENGTH_1024 1024 #define BUFF_LENGTH BUFF_LENGTH_1024 +#ifdef RDKV_TR69 +static const char* NOT_IMPLEMENTED = "Not Implemented"; + +static const char* STATE_UP = "Up"; +static const char* STATE_DOWN = "Down"; + +static const char* TIME_UNKNOWN = "0001-01-01T00:00:00Z"; +static const char* TIME_INFINITY = "9999-12-31T23:59:59Z"; +#endif + typedef enum __eSTBResetState { NoReset = 0, @@ -124,11 +134,13 @@ unsigned long string_to_ulong(const char *value); bool string_to_bool(const char *value); +std::string bool_to_string(bool value); + std::string getStringValue(HOSTIF_MsgData_t *stMsgData); void putValue(HOSTIF_MsgData_t *stMsgData, const std::string &value); -bool set_GatewayConnStatus(); +void set_GatewayConnStatus( bool enabled); bool get_GatewayConnStatus(); /** @@ -148,6 +160,10 @@ long timeValDiff(struct timespec *starttime, struct timespec *finishtime); void setLegacyRFCEnabled(bool value); bool legacyRFCEnabled(); #endif +#ifdef T2_EVENT_ENABLED +void t2CountNotify(const char *marker, int val); +void t2ValNotify(const char *marker, const char *val); +#endif HostIf_Source_Type_t getBSUpdateEnum(const char *bsUpdate); bool isWebpaReady(); diff --git a/src/hostif/parodusClient/gtest/Makefile.am b/src/hostif/parodusClient/gtest/Makefile.am index dbafed8ad..ba4a499bc 100644 --- a/src/hostif/parodusClient/gtest/Makefile.am +++ b/src/hostif/parodusClient/gtest/Makefile.am @@ -22,16 +22,16 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = dm_gtest # Define the include directories -COMMON_CPPFLAGS = -std=c++11 -I$(TOP_DIR)/src/unittest/stubs -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/parodusClient/waldb/ -I$(TOP_DIR)/src/hostif/parodusClient/pal/ -I$(TOP_DIR)/src/hostif/include/ -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/unittest/stubs/rbus/include +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -DUSE_DEV_PROPERTIES_CONF -DUSE_REMOTE_DEBUGGER -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I$(TOP_DIR)/src/hostif/handlers/include -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/hostif/httpserver/include -I$(TOP_DIR)/src/hostif/handlers/src -I/usr/include/rbus -I/usr/local/include/rbus -Isrc/unittest/stubs/rbus/include/ -I$(TOP_DIR)/src/hostif/profiles/Time -I$(TOP_DIR)/src/hostif/profiles/Device -I$(TOP_DIR)/src/hostif/profiles/IP -I$(TOP_DIR)/src/hostif/profiles/STBService -I/usr/rdk-halif-device_settings/include/ -I/usr/rdkvhal-devicesettings-raspberrypi4/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I$(TOP_DIR)/src/hostif/profiles/Ethernet -I/usr/remote_debugger/src/ -I/usr/local/include/libparodus/ -I/usr/local/include/wrp-c/ -I$(TOP_DIR)/src/hostif/parodusClient/startParodus/ -I/usr/include/libsoup-3.0 # Define the libraries to link against -COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lglib-2.0 -llibparodus -lwrp-c -lnanomsg -lmsgpackc -ltrower-base64 -lcimplog -lsoup-3.0 # Define the compiler flags COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) -fprofile-arcs -ftest-coverage -# Define the source files -dm_gtest_SOURCES = dm_test.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp + +dm_gtest_SOURCES = dm_test.cpp $(TOP_DIR)/src/hostif/parodusClient/startParodus/startParodus.cpp $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_NotificationHandler.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_notification.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_attribute.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_parameter.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/libpd.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_adapter.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_msgHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_XrdkCentralT2_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_IPClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_DeviceClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus_Process.cpp $(TOP_DIR)/src/hostif/profiles/Ethernet/Device_Ethernet_Interface.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_DisplayDevice.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_EthernetClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_TimeClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface.cpp $(TOP_DIR)/src/hostif/profiles/Time/Device_Time.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_updateHandler.cpp $(TOP_DIR)/src/hostif/profiles/Device/x_rdk_profile.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_dsClient_ReqHandler.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_rbus_Dml_Provider.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Capabilities.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_SPDIF.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_VideoDecoder.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_AudioOutput.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_HDMI.cpp $(TOP_DIR)/src/hostif/profiles/STBService/Components_VideoOutput.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface_Stats.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_ActivePort.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Diagnostics_IPPing.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface_IPv4Address.cpp $(TOP_DIR)/src/hostif/handlers/src/x_rdk_req_handler.cpp $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/unittest/stubs/wdmp-c.c $(TOP_DIR)/src/unittest/stubs/wdmp_internal.c $(TOP_DIR)/src/hostif/httpserver/src/http_server.cpp $(TOP_DIR)/src/hostif/httpserver/src/request_handler.cpp $(TOP_DIR)/src/hostif/httpserver/src/XrdkCentralComRFCVar.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.cpp $(TOP_DIR)/src/unittest/stubs/ds/libprocps.cpp $(TOP_DIR)/src/unittest/stubs/file_writer.cpp # Apply common properties to each program dm_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) diff --git a/src/hostif/parodusClient/gtest/dm_test.cpp b/src/hostif/parodusClient/gtest/dm_test.cpp index 27812bb8f..83f6dba14 100644 --- a/src/hostif/parodusClient/gtest/dm_test.cpp +++ b/src/hostif/parodusClient/gtest/dm_test.cpp @@ -19,17 +19,119 @@ #include #include #include +#include #include "dm_stubs.h" +#include "startParodus.h" +#include "file_writer.h" +#include "webpa_notification.h" +#include "webpa_parameter.h" +#include "webpa_adapter.h" +#include "libpd.h" +#include "webpa_attribute.h" +#include "rbus_value.h" +#include "hostIf_tr69ReqHandler.h" +#include "hostIf_utils.h" +#include "wrp-c.h" +#include "hostIf_msgHandler.h" +#include "Device_DeviceInfo_ProcessStatus_Process.h" +#include "cJSON.h" #include "waldb.h" #include "wdmp-c.h" using namespace std; + +#include +#include + #define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/" #define GTEST_DEFAULT_RESULT_FILENAME "datamodel_gtest_report.json" #define GTEST_REPORT_FILEPATH_SIZE 128 +extern GHashTable* paramMgrhash; + +std::mutex mtx_httpServerThreadDone; +std::condition_variable cv_httpServerThreadDone; +bool httpServerThreadDone = false; +GThread *HTTPServerThread = NULL; +char *HTTPServerName = (char *)"HTTPServerThread"; +GError *httpError = NULL; +GHashTable* paramMgrhash = NULL; +T_ARGLIST argList = {{'\0'}, 0}; + +typedef struct { + char name[512]; + char value[512]; + int statusCode; + char message[512]; +} ParsedResult; + +#ifdef GTEST_ENABLE +extern void (*macToLowerFunc())(char macValue[],char macConverted[]); +extern WDMP_STATUS (*GetParamInfoFunc()) (const char *pParameterName, param_t ***parametervalPtrPtr, int *paramCountPtr,int paramIndex); +extern rbusValueType_t (*getRbusDataTypefromWebPAFunc())(WAL_DATA_TYPE type); +extern DATA_TYPE (*mapRbusDataTypeToWebPAFunc())(rbusValueType_t type); +WDMP_STATUS (*get_ParamValues_tr69hostIfFunc()) (HOSTIF_MsgData_t *ptrParam, DataModelParam *dmParam); +WAL_STATUS (*set_ParamValues_tr69hostIfFunc()) (HOSTIF_MsgData_t *ptrParam); +WAL_STATUS (*convertFaultCodeToWalStatusFunc())(faultCode_t faultCode); +extern void (*converttohostIfTypeFunc())(char *ParamDataType,HostIf_ParamType_t* pParamType); +void (*converttoWalTypeFunc())(HostIf_ParamType_t paramType,WAL_DATA_TYPE* pwalType); +extern void (*get_parodus_urlFunc())(char *parodus_url, char *client_url); +extern WDMP_STATUS (*validate_parameterFunc()) (param_t *param, int paramCount); +extern WAL_STATUS (*get_AttribValues_tr69hostIfFunc()) (HOSTIF_MsgData_t *ptrParam); +extern WAL_STATUS (*set_AttribValues_tr69hostIfFunc()) (HOSTIF_MsgData_t *param); +extern WAL_STATUS (*getParamAttributesFunc()) (const char *pParameterName, AttrVal ***attr, int *TotalParams); +extern WAL_STATUS (*setParamAttributesFunc()) (const char *pParameterName, const AttrVal *attArr); +extern void (*setRebootReasonFunc()) (param_t param, WEBPA_SET_TYPE setType); +extern long (*timeValDiffFunc()) (struct timespec *starttime, struct timespec *finishtime); +extern WDMP_STATUS (*rbusGetParamInfoFunc()) (const char *pParameterName, param_t ***parametervalPtrPtr, int *paramCountPtr, int index); +extern WAL_STATUS (*rbusSetParamInfoFunc()) (ParamVal paramVal, char * transactionID); +extern WAL_STATUS (*SetParamInfoFunc()) (ParamVal paramVal, char * transactionID); +void (*parodus_receive_waitFunc()) (); +#endif + +int parse_json(char *json_str, ParsedResult *result) { + cJSON *root = cJSON_Parse(json_str); + if (!root) return 0; // parse error + + cJSON *statusCode = cJSON_GetObjectItem(root, "statusCode"); + if (cJSON_IsNumber(statusCode)) { + result->statusCode = statusCode->valueint; + } else { + cJSON_Delete(root); + return 0; + } + + cJSON *parameters = cJSON_GetObjectItem(root, "parameters"); + if (cJSON_IsArray(parameters)) { + cJSON *param = cJSON_GetArrayItem(parameters, 0); + if (param) { + cJSON *name = cJSON_GetObjectItem(param, "name"); + cJSON *value = cJSON_GetObjectItem(param, "value"); + cJSON *message = cJSON_GetObjectItem(param, "message"); + + if (cJSON_IsString(name)) { + strncpy(result->name, name->valuestring, sizeof(result->name) - 1); + result->name[sizeof(result->name) - 1] = '\0'; + } + + if (cJSON_IsString(value)) { + strncpy(result->value, value->valuestring, sizeof(result->value) - 1); + result->value[sizeof(result->value) - 1] = '\0'; + } + + if (cJSON_IsString(message)) { + strncpy(result->message, message->valuestring, sizeof(result->message) - 1); + result->message[sizeof(result->message) - 1] = '\0'; + } + } + } + + cJSON_Delete(root); + return 1; // success +} + TEST(datamodelTest, ParameterExistPositive2) { /* Load the data model xml file*/ @@ -158,6 +260,1075 @@ TEST(datamodelTest, ParameterListTest) { DataModelParam dmParam = {0}; } +TEST(datamodelTest, getNumberofInstances) { + int cnt = getNumberofInstances("Device.IP.Interface.{i}."); + EXPECT_EQ(0, 0); + +} + +TEST(datamodelTest, isWildCardParam) { + int wildParam = isWildCardParam("Device.DeviceInfo."); + EXPECT_EQ(wildParam, 1); +} + +TEST(datamodelTest, isParamEndsWithInstance) { + int instance = isParamEndsWithInstance("Device.IP.Interface.{i}."); + EXPECT_EQ(instance, 0); +} + +TEST(datamodelTest, getNumberOfDigitsInInstanceNumber) { + int instance = getNumberOfDigitsInInstanceNumber("Device.WiFi.SSID.123.Name", 17); + EXPECT_EQ(instance, 3); +} + +TEST(datamodelTest, getChildParamNamesFromDataModel) { + + /* Load the data model xml file*/ + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + char *ParamList = NULL; + char *ParamDataTypeList = NULL; + + char *paramName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.VideoTelemetry."; + int paramCount = 1; + DB_STATUS status = getChildParamNamesFromDataModel(getDataModelHandle(), paramName, &ParamList, &ParamDataTypeList, ¶mCount); + EXPECT_EQ(status, DB_SUCCESS); +} + +TEST(datamodelTest, getChildParamNamesFromDataModel_InvalidParam) { + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + char *ParamList = NULL; + char *ParamDataTypeList = NULL; + + char *paramName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.FriendlyName"; + int paramCount = 1; + DB_STATUS status = getChildParamNamesFromDataModel(getDataModelHandle(), paramName, &ParamList, &ParamDataTypeList, ¶mCount); + EXPECT_EQ(status, 2); +} + +TEST(datamodelTest, checkDataModelStatus) { + DB_STATUS status = checkDataModelStatus(); + EXPECT_EQ(status, DB_SUCCESS); +} + +TEST(datamodelTest, checkMatchingParameter) { + const char* attrValue = "a.b.c.{i}."; + char* paramName = "a.b.c.1."; + int ret = 0; + int retValue = checkMatchingParameter(attrValue, paramName, &ret); + EXPECT_EQ(retValue, 1); +} + +TEST(startParodusTest, get_HWMAcAddress) { + write_on_file("/tmp/.macAddress", "D4:52:EE:DE:C6:FA"); + std::string macAddr = get_HWMAcAddress(); + EXPECT_EQ(macAddr, "D452EEDEC6FA"); +} + +TEST(startParodusTest, get_PartnerId_Empty) { + write_on_file("/opt/www/authService/partnerId3.dat", ""); + std::string partnerId = get_PartnerId(); + EXPECT_EQ(partnerId, "*,"); +} + +TEST(startParodusTest, get_PartnerId) { + write_on_file("/opt/www/authService/partnerId3.dat", "sky"); + std::string partnerId = get_PartnerId(); + EXPECT_EQ(partnerId, "*,sky"); +} + +TEST(startParodusTest, get_PartnerId_Unknown) { + std::remove("/opt/www/authService/partnerId3.dat"); + write_on_file("/opt/www/authService/partnerId3.dat", "unknown"); + std::string partnerId = get_PartnerId(); + EXPECT_EQ(partnerId, "unknown"); + std::remove("/opt/www/authService/partnerId3.dat"); +} + +TEST(startParodusTest, get_RebootReason_Empty) { + write_on_file("/opt/secure/reboot/previousreboot.info", ""); + std::string reboot_reason = get_RebootReason(); + EXPECT_EQ(reboot_reason, ""); +} + +TEST(startParodusTest, get_RebootReason) { + std::string jsonData = "{\"reason\": \"PowerOnReset\", \"timestamp\": 1688914800}"; + write_on_file("/opt/secure/reboot/previousreboot.info", jsonData); + std::string reboot_reason = get_RebootReason(); + EXPECT_EQ(reboot_reason, "PowerOnReset"); +} + +TEST(startParodusTest, get_FwName) { + write_on_file("/version.txt", "imagename:ELTE11MWR_VBN_25Q3_sprint_20250814010729sdy_NG"); + std::string fw_name = get_FwName(); + EXPECT_EQ(fw_name, "ELTE11MWR_VBN_25Q3_sprint_20250814010729sdy_NG"); +} + +TEST(palTest, macToLower) { + char macValue[32] = "A8:4A:63:88:E9:B5"; + char macConverted[32]; + macConverted[0] = '\0'; + macToLowerFunc()(macValue, macConverted); + EXPECT_STREQ(macConverted, "a84a6388e9b5"); +} + +TEST(palTest, getnotifyparamList_Empty) { + setNotifyConfigurationFile("/tmp/empty.conf"); + char **notifyParamList = NULL; + int ptrnotifyListSize = 3; + int ret = getnotifyparamList(¬ifyParamList, &ptrnotifyListSize); + EXPECT_EQ(ret, -1); +} + +TEST(palTest, getnotifyparamList) { + const char* json_data = R"({"Notify":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpStart","Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpEnd"]})"; + write_on_file("/tmp/notify.conf", json_data); + char **notifyParamList = NULL; + int ptrnotifyListSize = 3; + setNotifyConfigurationFile("/tmp/notify.conf"); + int ret = getnotifyparamList(¬ifyParamList, &ptrnotifyListSize); + EXPECT_EQ(ret, 0); +} + +/* TEST(palTest, getParamAttributes_Canary) { + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + + const char *paramName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpStart"; + AttrVal **attributes = NULL; + int totalParams = 1; + + WAL_STATUS status = getParamAttributesFunc()(paramName, &attributes, &totalParams); + EXPECT_EQ(status, WAL_SUCCESS); +} */ + +TEST(palTest, getNotifySource_Empty) { + char* notificationSource = getNotifySource(); + EXPECT_EQ(0, 0); +} + +TEST(palTest, getNotifySource) { + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + char* notificationSource = getNotifySource(); + EXPECT_EQ(0, 0); +} + +TEST(palTest, setNotifyConfigurationFile) { + setNotifyConfigurationFile(NULL); + EXPECT_EQ(0, 0); +} + +TEST(palTest, getRbusDataTypefromWebPA) { + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_STRING), RBUS_STRING); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_INT), RBUS_INT32); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_UINT), RBUS_UINT32); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_BOOLEAN), RBUS_BOOLEAN); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_DATETIME), RBUS_DATETIME); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_BASE64), RBUS_BYTES); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_LONG), RBUS_INT64); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_ULONG), RBUS_UINT64); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_FLOAT), RBUS_SINGLE); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_DOUBLE), RBUS_DOUBLE); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_BYTE), RBUS_BYTE); + EXPECT_EQ(getRbusDataTypefromWebPAFunc()(WAL_NONE), RBUS_STRING); +} + +TEST(palTest, mapRbusDataTypeToWebPA) { + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_BOOLEAN), WDMP_BOOLEAN); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_CHAR), WDMP_BYTE); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_INT16), WDMP_INT); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_UINT16), WDMP_UINT); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_INT64), WDMP_LONG); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_UINT64), WDMP_ULONG); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_STRING), WDMP_STRING); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_DATETIME), WDMP_DATETIME); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_DATETIME), WDMP_DATETIME); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_BYTES), WDMP_BASE64); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_SINGLE), WDMP_FLOAT); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_DOUBLE), WDMP_DOUBLE); + EXPECT_EQ(mapRbusDataTypeToWebPAFunc()(RBUS_PROPERTY), WDMP_NONE); +} + +TEST(palTest, get_ParamValues_tr69hostIf) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_IntegerType; + param.paramLen = sizeof(hostIf_IntegerType); + + DataModelParam dmParam = {0}; + const char* dbParamName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed"; + int match = getParamInfoFromDataModel(getDataModelHandle(), dbParamName, &dmParam); + + WDMP_STATUS status = get_ParamValues_tr69hostIfFunc()(¶m, &dmParam); + EXPECT_EQ(0, 0); +} + +TEST(palTest, set_ParamValues_tr69hostIf) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.LowSpeed", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_int(param.paramValue, 13800); + param.paramtype = hostIf_IntegerType; + param.paramLen = sizeof(hostIf_IntegerType); + + WAL_STATUS status = set_ParamValues_tr69hostIfFunc()(¶m); + EXPECT_EQ(0, 0); +} +TEST(palTest, convertFaultCodeToWalStatus) { + EXPECT_EQ(convertFaultCodeToWalStatusFunc()(fcNoFault), WAL_FAILURE); + EXPECT_EQ(convertFaultCodeToWalStatusFunc()(fcAttemptToSetaNonWritableParameter), WAL_ERR_NOT_WRITABLE); + EXPECT_EQ(convertFaultCodeToWalStatusFunc()(fcInvalidParameterName), WAL_ERR_INVALID_PARAMETER_NAME); + EXPECT_EQ(convertFaultCodeToWalStatusFunc()(fcInvalidParameterType), WAL_ERR_INVALID_PARAMETER_TYPE); + EXPECT_EQ(convertFaultCodeToWalStatusFunc()(fcInvalidParameterValue), WAL_ERR_INVALID_PARAMETER_VALUE); + EXPECT_EQ(convertFaultCodeToWalStatusFunc()(fcInternalError), WAL_FAILURE); +} + +TEST(palTest, isWildCardParam) { + int ret = isWildCardParam("Device.DeviceInfo."); + EXPECT_EQ(ret, 1); +} + +TEST(palTest, converttohostIfType) { + HostIf_ParamType_t pParamType; + + converttohostIfTypeFunc()("string", &pParamType); + EXPECT_EQ(pParamType, hostIf_StringType); + + converttohostIfTypeFunc()("unsignedInt", &pParamType); + EXPECT_EQ(pParamType, hostIf_UnsignedIntType); + + converttohostIfTypeFunc()("int", &pParamType); + EXPECT_EQ(pParamType, hostIf_IntegerType); + + converttohostIfTypeFunc()("unsignedLong", &pParamType); + EXPECT_EQ(pParamType, hostIf_UnsignedLongType); + + converttohostIfTypeFunc()("boolean", &pParamType); + EXPECT_EQ(pParamType, hostIf_BooleanType); + + converttohostIfTypeFunc()("hexBinary", &pParamType); + EXPECT_EQ(pParamType, hostIf_StringType); + + converttohostIfTypeFunc()("float", &pParamType); + EXPECT_EQ(pParamType, hostIf_StringType); +} + +TEST(palTest, GetParamInfo) { + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + const char *pParameterName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable"; + param_t** parameterval = (param_t**) calloc(1, sizeof(param_t*)); + EXPECT_NE(parameterval, nullptr); + int paramCountPtr = 0; + int index = 0; + WDMP_STATUS status = GetParamInfoFunc()(pParameterName, ¶meterval, ¶mCountPtr, index); + EXPECT_EQ(0, 0); +} + +TEST(palTest, GetParamInfo_UnsignedInt) { + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + const char *pParameterName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.collectd.PortNumber"; + param_t** parameterval = (param_t**) calloc(1, sizeof(param_t*)); + EXPECT_NE(parameterval, nullptr); + int paramCountPtr = 0; + int index = 0; + WDMP_STATUS status = GetParamInfoFunc()(pParameterName, ¶meterval, ¶mCountPtr, index); + EXPECT_EQ(0, 0); +} + +TEST(palTest, GetParamInfo_String) { + + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + const char *pParameterName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName"; + param_t** parameterval = (param_t**) calloc(1, sizeof(param_t*)); + EXPECT_NE(parameterval, nullptr); + int paramCountPtr = 0; + int index = 0; + WDMP_STATUS status = GetParamInfoFunc()(pParameterName, ¶meterval, ¶mCountPtr, index); + EXPECT_EQ(0, 0); +} + +TEST(palTest, SetParamInfoFunc_Bool) { + + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + ParamVal param; + param.name = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.IncrementalCDL.Enable"; + param.value = "false"; + param.type = WAL_BOOLEAN; + + char transactionID[] = "txn12344"; + + WAL_STATUS status = SetParamInfoFunc() (param, transactionID); + EXPECT_EQ(status, WAL_SUCCESS); +} + + +TEST(palTest, SetParamInfoFunc_Int) { + + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + ParamVal param; + param.name = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.LowSpeed"; + param.value = "14800"; + param.type = WAL_INT; + + char transactionID[] = "txn12344"; + + WAL_STATUS status = SetParamInfoFunc() (param, transactionID); + EXPECT_EQ(status, WAL_SUCCESS); +} + +TEST(palTest, SetParamInfoFunc_String) { + + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + DB_STATUS dbStatus = loadDataModel(); + if(dbStatus != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(dbStatus, DB_SUCCESS); + ParamVal param; + param.name = "Device.X_RDKCENTRAL-COM_T2.ReportProfiles"; + param.value = "TestProfiles"; + param.type = WAL_STRING; + + char transactionID[] = "txn12344"; + + WAL_STATUS status = SetParamInfoFunc() (param, transactionID); + EXPECT_EQ(status, WAL_SUCCESS); +} + +TEST(palTest, GetWildParamInfo) { + const char *pParameterName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit."; + param_t **parametervalPtrPtr = (param_t**) calloc(3, sizeof(param_t*)); + int paramCountPtr = 3; + int index = 0; + WDMP_STATUS status = GetParamInfoFunc()(pParameterName, ¶metervalPtrPtr, ¶mCountPtr, index); + EXPECT_EQ(status, WDMP_SUCCESS); + + for (int i = 0; i < 3; i++) { + if (parametervalPtrPtr[i]) { + // If parametervalPtrPtr[i] points to dynamically allocated memory, free it + free(parametervalPtrPtr[i]); + parametervalPtrPtr[i] = NULL; + } + } + free(parametervalPtrPtr); + parametervalPtrPtr = NULL; +} + +TEST(palTest, GetWildParamInfo_String) { + const char *pParameterName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger."; + param_t **parametervalPtrPtr = (param_t**) calloc(4, sizeof(param_t*)); + int paramCountPtr = 4; + int index = 0; + WDMP_STATUS status = GetParamInfoFunc()(pParameterName, ¶metervalPtrPtr, ¶mCountPtr, index); + EXPECT_EQ(status, WDMP_SUCCESS); + + for (int i = 0; i < 4; i++) { + if (parametervalPtrPtr[i]) { + // If parametervalPtrPtr[i] points to dynamically allocated memory, free it + free(parametervalPtrPtr[i]); + parametervalPtrPtr[i] = NULL; + } + } + free(parametervalPtrPtr); + parametervalPtrPtr = NULL; +} + + +TEST(palTest, get_parodus_url_EmptyConfigFileSetsDefaults) { + // Write empty config file + std::ofstream ofs("/etc/webpa_cfg.json"); + ofs.close(); + char parodus_url[64] = {'\0'}; + char client_url[64] = {'\0'}; + get_parodus_urlFunc()(parodus_url, client_url); + EXPECT_NE(parodus_url, ""); + EXPECT_NE(client_url, ""); +} + +TEST(palPdTest, get_parodus_url_MissingConfigFileSetsDefaults) { + unlink("/etc/webpa_cfg.json"); + char parodus_url[64] = {'\0'}; + char client_url[64] = {'\0'}; + get_parodus_urlFunc()(parodus_url, client_url); + EXPECT_NE(parodus_url, ""); + EXPECT_NE(client_url, ""); +} + +TEST(palTest, get_parodus_url) { + char parodus_url[256] = {0}; + char client_url[256] = {0}; + const char *webpaCfgFile = "{ \"ParodusURL\": \"tcp://parodus.xcal.tv:6666\", \"ParodusClientURL\": \"tcp://127.0.0.1:6666\" }"; + write_on_file("/etc/webpa_cfg.json", webpaCfgFile); + get_parodus_urlFunc()(parodus_url, client_url); + EXPECT_STREQ(parodus_url, "tcp://parodus.xcal.tv:6666"); + EXPECT_STREQ(client_url, "tcp://127.0.0.1:6666"); +} + +/*TEST(LibPdTest, sendNotification_ValidPayloadSends) { + // This requires a mock/fake for libparodus_send, wrp_free_struct, etc. + // For now, ensure function does not crash with valid input + char payload[] = "{\"command\":\"GET\",\"names\":[\"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed\"]}"; + char source[] = "source"; + char dest[] = "dest"; + sendNotification(payload, source, dest); + EXPECT_EQ(0, 0); +} */ + +TEST(palTest, validate_parameter_wildcard) { + param_t *params = (param_t *) malloc(sizeof(param_t) * 1); + + params[0].name = strdup("Device.DeviceInfo."); + params[0].value = strdup("true"); + params[0].type = WDMP_BOOLEAN; + int paramCount = 1; + + WDMP_STATUS status = validate_parameterFunc()(params, paramCount); + EXPECT_EQ(status, WDMP_ERR_WILDCARD_NOT_SUPPORTED); +} + +TEST(palTest, validate_parameter_Null) { + param_t *params = (param_t *) malloc(sizeof(param_t) * 1); + + int paramCount = 1; + params[0].name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.Enable"); + params[0].value = NULL; + params[0].type = WDMP_BOOLEAN; + + WDMP_STATUS status = validate_parameterFunc()(params, paramCount); + EXPECT_EQ(status, WDMP_ERR_VALUE_IS_NULL); + + free(params[0].name); + free(params[0].value); + free(params); +} + +TEST(palTest, validate_parameter_NOT_Support) { + param_t *params = (param_t *) malloc(sizeof(param_t) * 1); + + int paramCount = 1; + params[0].name = strdup("Device.DeviceInfo.Webpa.X_COMCAST-COM_CMC"); + params[0].value = strdup("test"); + params[0].type = WDMP_BOOLEAN; + + WDMP_STATUS status = validate_parameterFunc()(params, paramCount); + EXPECT_EQ(status, WDMP_ERR_SET_OF_CMC_OR_CID_NOT_SUPPORTED); + + free(params[0].name); + free(params[0].value); + free(params); +} + +TEST(palTest, processRequest_GET) { + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + //Load the data model xml file + DB_STATUS status = loadDataModel(); + if(status != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(status, DB_SUCCESS); + + wrp_msg_t *wrp_msg; + wrp_msg_t *res_wrp_msg; + + wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t)); + res_wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t)); + memset(res_wrp_msg, 0, sizeof(wrp_msg_t)); + wrp_msg->msg_type = WRP_MSG_TYPE__REQ; + + const char *payload = "{\"command\":\"GET\",\"names\":[\"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed\"]}"; + wrp_msg->u.req.payload = (void*)payload; + + wrp_msg->u.req.payload_size = strlen((char*)wrp_msg->u.req.payload); + processRequest((char*)wrp_msg->u.req.payload, (char*)wrp_msg->u.req.transaction_uuid, ((char **)(&(res_wrp_msg->u.req.payload)))); + std::cout << "Response payload: " << (char*)res_wrp_msg->u.req.payload << std::endl; + char *json_response = (char*)res_wrp_msg->u.req.payload; + + ParsedResult result = {0}; + if (parse_json(json_response, &result)) + { + EXPECT_EQ(result.statusCode, 200); + EXPECT_STREQ(result.message, "Success"); + EXPECT_STREQ(result.name, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed"); + EXPECT_STREQ(result.value, "1280000"); + } +} + +TEST(palTest, processRequest_GETWildCard) { + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + //Load the data model xml file + DB_STATUS status = loadDataModel(); + if(status != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(status, DB_SUCCESS); + wrp_msg_t *wrp_msg; + wrp_msg_t *res_wrp_msg; + + wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t)); + res_wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t)); + memset(res_wrp_msg, 0, sizeof(wrp_msg_t)); + wrp_msg->msg_type = WRP_MSG_TYPE__REQ; + const char *payload = "{\"command\":\"GET_ATTRIBUTES\",\"attributes\":\"notify\",\"names\":[\"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.\"]}"; + wrp_msg->u.req.payload = (void*)payload; + wrp_msg->u.req.payload_size = strlen((char*)wrp_msg->u.req.payload); + processRequest((char*)wrp_msg->u.req.payload, (char*)wrp_msg->u.req.transaction_uuid, ((char **)(&(res_wrp_msg->u.req.payload)))); + std::cout << "Response payload: " << (char*)res_wrp_msg->u.req.payload << std::endl; + char *json_response = (char*)res_wrp_msg->u.req.payload; + EXPECT_EQ(0, 0); +} + +TEST(palTest, processRequest_SET) { + // Load the data model xml file + DB_STATUS status = loadDataModel(); + if(status != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(status, DB_SUCCESS); + + wrp_msg_t *wrp_msg; + wrp_msg_t *res_wrp_msg; + + wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t)); + res_wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t)); + memset(res_wrp_msg, 0, sizeof(wrp_msg_t)); + wrp_msg->msg_type = WRP_MSG_TYPE__REQ; + + const char *payload = "{\"command\":\"SET\",\"parameters\":[{\"name\":\"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.LogUpload.LogServerUrl\",\"dataType\":0,\"value\":\"logs.xcal.tv\"}]}"; + wrp_msg->u.req.payload = (void*)payload; + + wrp_msg->u.req.payload_size = strlen((char*)wrp_msg->u.req.payload); + processRequest((char*)wrp_msg->u.req.payload, (char*)wrp_msg->u.req.transaction_uuid, ((char **)(&(res_wrp_msg->u.req.payload)))); + std::cout << "Response payload: " << (char*)res_wrp_msg->u.req.payload << std::endl; + char *json_response = (char*)res_wrp_msg->u.req.payload; + + ParsedResult result = {0}; + if (parse_json(json_response, &result)) + { + EXPECT_EQ(result.statusCode, 200); + EXPECT_STREQ(result.message, "Success"); + EXPECT_STREQ(result.name, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.LogUpload.LogServerUrl"); + } +} + +TEST(srcTest, getCurrentTime) { + struct timespec ts; + getCurrentTime(&ts); + EXPECT_GT(ts.tv_sec, 0); + + EXPECT_GE(ts.tv_nsec, 0); + EXPECT_LT(ts.tv_nsec, 1000000000L); +} + +TEST(srcTest, setInitialNotifyConfigFile) { + std::remove("/tmp/notify.conf"); + const char* json_data = R"({"Notify":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.Enable","Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed"]})"; + write_on_file("/tmp/notify.conf", json_data); + char **notifyParamList = NULL; + int ptrnotifyListSize = 2; + setInitialNotifyConfigFile("/tmp/notify.conf"); + int ret = getnotifyparamList(¬ifyParamList, &ptrnotifyListSize); + setInitialNotify(); + EXPECT_EQ(0, 0); +} + +/* TEST(palTest, get_AttribValues_tr69hostIf) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + WAL_STATUS status = get_AttribValues_tr69hostIfFunc()(¶m); + EXPECT_EQ(status, WAL_ERR_INVALID_PARAM); +} */ + +TEST(palTest, set_AttribValues_tr69hostIf) { + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + WAL_STATUS status = set_AttribValues_tr69hostIfFunc()(¶m); + EXPECT_EQ(status, WAL_SUCCESS); +} + +TEST(palTest, getParamAttributes) { + + const char *paramName = "Device.WiFi.SSID.1.SSID"; + AttrVal **attributes = NULL; + int totalParams = 0; + + WAL_STATUS status = getParamAttributesFunc()(paramName, &attributes, &totalParams); + EXPECT_EQ(status, WAL_ERR_INVALID_PARAM); +} + +TEST(palTest, setParamAttributes) { + + const char *paramName = "Device.WiFi.SSID.1.SSID"; + AttrVal attr; + + WAL_STATUS status = setParamAttributesFunc()(paramName, &attr); + EXPECT_EQ(status, WAL_SUCCESS); +} + +TEST(palTest, setParamAttributes_notifyList) { + std::remove("/tmp/notify.conf"); + const char* json_data = R"({"Notify":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.Enable","Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed"]})"; + write_on_file("/tmp/notify.conf", json_data); + char **notifyParamList = NULL; + int ptrnotifyListSize = 3; + setNotifyConfigurationFile("/tmp/notify.conf"); + int ret = getnotifyparamList(¬ifyParamList, &ptrnotifyListSize); + const char *paramName = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed"; + AttrVal attr; + + attr.name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed"); + attr.value = strdup("168000"); + + WAL_STATUS status = setParamAttributesFunc()(paramName, &attr); + EXPECT_EQ(status, WAL_SUCCESS); +} + +TEST(palTest, getAttributes) { + const char *paramNames[] = { + "Device.DeviceInfo.ModelName", + "Device.DeviceInfo.SerialNumber" + }; + unsigned int paramCount = sizeof(paramNames) / sizeof(paramNames[0]); + + money_trace_spans span = {0}; // Optional, or nullptr + + AttrVal **attrArray = nullptr; + int attrCount = 0; + WAL_STATUS status = WAL_FAILURE; + + getAttributes(paramNames, paramCount, &span, &attrArray, &attrCount, &status); + + EXPECT_EQ(status, 14); +} + +TEST(palTest, setAttributes) { + std::remove("/tmp/notify.conf"); + const char* json_data = R"({"Notify":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable"]})"; + write_on_file("/tmp/notify.conf", json_data); + char **notifyParamList = NULL; + int ptrnotifyListSize = 1; + setNotifyConfigurationFile("/tmp/notify.conf"); + int ret = getnotifyparamList(¬ifyParamList, &ptrnotifyListSize); + + ParamVal params[1]; + params[0].name = strdup("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable"); + params[0].value = strdup("true"); + params[0].type = WAL_BOOLEAN; + + unsigned int paramCount = 1; + money_trace_spans traceSpan = {0}; + AttrVal val1 = { (char *)"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable", (char *)"true", WAL_BOOLEAN }; + const AttrVal *attrList[1] = { &val1 }; + WDMP_STATUS* statuses = new WDMP_STATUS[1]; + + setAttributes(params, paramCount, &traceSpan, attrList, &statuses); + EXPECT_EQ(0, 0); +} + +/* TEST(webpaAdapterTest, setRebootReason) { + + strcpy(argList.confFile, "/etc/mgrlist.conf"); + bool ret = hostIf_initalize_ConfigManger(); + + //Load the data model xml file + DB_STATUS status = loadDataModel(); + if(status != DB_SUCCESS) + { + std::cout << "Error in Data Model Initialization" << std::endl; + } + else + { + std::cout << "Successfully initialize Data Model." << std::endl; + } + EXPECT_EQ(status, DB_SUCCESS); + + // Prepare a param_t with the reboot parameter and value + param_t param; + param.name = strdup("Device.X_CISCO_COM_DeviceControl.RebootDevice"); + param.value = strdup("Device"); + param.type = WDMP_STRING; + + // Call setRebootReason and check for no crash (L1) + setRebootReasonFunc()(param, WEBPA_SET); + + // Clean up + free(param.name); + free(param.value); + + // L1: No assertion needed, just ensure no crash + EXPECT_EQ(0, 0); +} */ + + +TEST(palTest, parodus_receive_waitFunc) { + parodus_receive_waitFunc(); + sleep(30); + stop_parodus_recv_wait(); + EXPECT_EQ(0, 0); +} + +TEST(palTest, stop_parodus_recv_wait) { + stop_parodus_recv_wait(); + EXPECT_EQ(0, 0); +} + +TEST(palTest, notificationCallBack) { + notificationCallBack(); + EXPECT_EQ(0, 0); +} + +TEST(palTest, setInitialNotify) { + notificationCallBack(); + EXPECT_EQ(0, 0); +} + +TEST(palTest, libpd_set_notifyConfigFile) { + std::remove("/tmp/notify.conf"); const char* json_data = R"({"Notify":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.Enable","Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed"]})"; + write_on_file("/tmp/notify.conf", json_data); + char **notifyParamList = NULL; + int ptrnotifyListSize = 2; + libpd_set_notifyConfigFile("/tmp/notify.conf"); + EXPECT_EQ(0, 0); +} + +TEST(palTest, registerNotifyCallback) { + registerNotifyCallback(); + EXPECT_EQ(0, 0); +} + +TEST(palTest, timeValDiff) { + struct timespec starttime = { + .tv_sec = 100, + .tv_nsec = 500000000 // 0.5 seconds + }; + + struct timespec endtime = { + .tv_sec = 102, + .tv_nsec = 200000000 // 0.2 seconds + }; + + long msec = timeValDiffFunc()(&starttime, &endtime); + EXPECT_EQ(msec, 1700); +} + +TEST(palTest, replaceWithInstanceNumber) { + char paramName[50] = "Device.DeviceInfo.XXXX.{i}"; + int instanceNumber = 3; + replaceWithInstanceNumber(paramName, instanceNumber); + EXPECT_STREQ(paramName, "Device.DeviceInfo.XXXX.{i}"); +} + +TEST(palTest, appendNextObject) { + char currentParam[100] = "Device.WiFi.{i}.SSID."; + const char* pAttparam = "Device.WiFi.{i}.SSID.Enable"; + appendNextObject(currentParam, pAttparam); + + EXPECT_STREQ(currentParam, "Device.WiFi.{i}.SSID.Enable"); +} + +TEST(palTest, test_get_complete_param_list) { + test_get_complete_param_list(); + EXPECT_EQ(0, 0); +} + +TEST(palTest, converttoWalType) { + WAL_DATA_TYPE walType = WAL_STRING; + + converttoWalTypeFunc()(hostIf_IntegerType, &walType); + EXPECT_EQ(walType, WAL_INT); + + converttoWalTypeFunc()(hostIf_UnsignedIntType, &walType); + EXPECT_EQ(walType, WAL_UINT); + + converttoWalTypeFunc()(hostIf_BooleanType, &walType); + EXPECT_EQ(walType, WAL_BOOLEAN); + + converttoWalTypeFunc()(hostIf_UnsignedLongType, &walType); + EXPECT_EQ(walType, WAL_ULONG); + + converttoWalTypeFunc()(hostIf_DateTimeType, &walType); + EXPECT_EQ(walType, WAL_DATETIME); +} + +TEST(palTest, rbusSetParamInfo) { + ParamVal param; + param.name = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.Enable"; + param.value = "true"; + param.type = WAL_BOOLEAN; + + char transactionID[] = "txn12345"; + + WAL_STATUS status = rbusSetParamInfoFunc() (param, transactionID); + EXPECT_EQ(status, WAL_SUCCESS); +} + +TEST(palTest, getnotifyparamList_NULL) { + char **dummyList = NULL; + int result = getnotifyparamList(&dummyList, NULL); + EXPECT_EQ(result, -1); + + int dummySize = 0; + int ret = getnotifyparamList(NULL, &dummySize); + EXPECT_EQ(ret, -1); +} + +TEST(ProcessStatus, DeviceInfo_ProcessStatus_Process_PID) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.ProcessStatus.Process.1.PID", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceProcess *hostIf_DeviceProcess = hostIf_DeviceProcess::getInstance(instanceNumber); + if(hostIf_DeviceProcess) + { + bChanged = false; + int ret = hostIf_DeviceProcess->get_Device_DeviceInfo_ProcessStatus_Process_PID(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(ProcessStatus, DeviceInfo_ProcessStatus_Process_Command) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.ProcessStatus.Process.1.Command", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceProcess *hostIf_DeviceProcess = hostIf_DeviceProcess::getInstance(instanceNumber); + if(hostIf_DeviceProcess) + { + bChanged = false; + int ret = hostIf_DeviceProcess->get_Device_DeviceInfo_ProcessStatus_Process_PID(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(ProcessStatus, DeviceInfo_ProcessStatus_Process_Size) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.ProcessStatus.Process.1.Size", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceProcess *hostIf_DeviceProcess = hostIf_DeviceProcess::getInstance(instanceNumber); + if(hostIf_DeviceProcess) + { + bChanged = false; + int ret = hostIf_DeviceProcess->get_Device_DeviceInfo_ProcessStatus_Process_PID(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(ProcessStatus, DeviceInfo_ProcessStatus_Process_Priority) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.ProcessStatus.Process.1.Priority", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceProcess *hostIf_DeviceProcess = hostIf_DeviceProcess::getInstance(instanceNumber); + if(hostIf_DeviceProcess) + { + bChanged = false; + int ret = hostIf_DeviceProcess->get_Device_DeviceInfo_ProcessStatus_Process_PID(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(ProcessStatus, DeviceInfo_ProcessStatus_Process_CPUTime) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.ProcessStatus.Process.1.CPUTime", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceProcess *hostIf_DeviceProcess = hostIf_DeviceProcess::getInstance(instanceNumber); + if(hostIf_DeviceProcess) + { + bChanged = false; + int ret = hostIf_DeviceProcess->get_Device_DeviceInfo_ProcessStatus_Process_PID(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(ProcessStatus, DeviceInfo_ProcessStatus_Process_State) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.ProcessStatus.Process.1.State", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceProcess *hostIf_DeviceProcess = hostIf_DeviceProcess::getInstance(instanceNumber); + if(hostIf_DeviceProcess) + { + bChanged = false; + int ret = hostIf_DeviceProcess->get_Device_DeviceInfo_ProcessStatus_Process_PID(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} GTEST_API_ int main(int argc, char *argv[]){ char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE]; diff --git a/src/hostif/parodusClient/pal/libpd.cpp b/src/hostif/parodusClient/pal/libpd.cpp index 65a652358..d21935651 100644 --- a/src/hostif/parodusClient/pal/libpd.cpp +++ b/src/hostif/parodusClient/pal/libpd.cpp @@ -450,3 +450,21 @@ static long timeValDiff(struct timespec *starttime, struct timespec *finishtime) msec+=(finishtime->tv_nsec-starttime->tv_nsec)/1000000; return msec; } + +#ifdef GTEST_ENABLE +void (*get_parodus_urlFunc())(char *parodus_url, char *client_url) +{ + return &get_parodus_url; +} + +long (*timeValDiffFunc()) (struct timespec *starttime, struct timespec *finishtime) +{ + return &timeValDiff; +} + +void (*parodus_receive_waitFunc()) () +{ + return &parodus_receive_wait; +} + +#endif diff --git a/src/hostif/parodusClient/pal/mock-parodus/Makefile.am b/src/hostif/parodusClient/pal/mock-parodus/Makefile.am new file mode 100644 index 000000000..1e789bd95 --- /dev/null +++ b/src/hostif/parodusClient/pal/mock-parodus/Makefile.am @@ -0,0 +1,75 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2024 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################## + +bin_PROGRAMS = parodus +PARODUS_INSTALL_DIR = /usr/local +LOCAL_DIR = /usr/local + + +parodus_SOURCES = \ + parodus.cpp \ + ../webpa_notification.cpp \ + ../libpd.cpp \ + ../webpa_parameter.cpp \ + ../webpa_adapter.cpp ../webpa_attribute.cpp \ + ../../../handlers/src/hostIf_msgHandler.cpp \ + ../../../src/hostIf_utils.cpp \ + ../../../handlers/src/hostIf_NotificationHandler.cpp \ + ../../../handlers/src/hostIf_TimeClient_ReqHandler.cpp \ + ../../../profiles/Time/Device_Time.cpp \ + ../../../profiles/DeviceInfo/XrdkCentralComBSStore.cpp \ + ../../../profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp \ + ../../../profiles/DeviceInfo/Device_DeviceInfo.cpp \ + ../../../handlers/src/hostIf_DeviceClient_ReqHandler.cpp \ + ../../../profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus_Process.cpp \ + ../../../handlers/src/hostIf_EthernetClient_ReqHandler.cpp \ + ../../../profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp \ + ../../../profiles/Ethernet/Device_Ethernet_Interface.cpp \ + ../../../profiles/DeviceInfo/XrdkCentralComRFC.cpp \ + ../../../profiles/DeviceInfo/XrdkCentralComRFCStore.cpp \ + ../../../profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp \ + ../../../profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.cpp \ + ../../../src/IniFile.cpp \ + ../../../../unittest/stubs/powerctrl_stubs.cpp \ + ../../../../unittest/stubs/paramMgr.c \ + ../../../handlers/src/hostIf_IPClient_ReqHandler.cpp \ + ../../../profiles/IP/Device_IP_Interface.cpp \ + ../../../profiles/IP/Device_IP.cpp \ + ../../../profiles/IP/Device_IP_Interface_IPv4Address.cpp \ + ../../../profiles/IP/Device_IP_Diagnostics_IPPing.cpp \ + ../../../profiles/IP/Device_IP_Interface_Stats.cpp \ + ../../../profiles/IP/Device_IP_ActivePort.cpp \ + ../../../handlers/src/hostIf_updateHandler.cpp \ + ../../../handlers/src/hostIf_dsClient_ReqHandler.cpp \ + ../../../profiles/STBService/Components_VideoOutput.cpp \ + ../../../profiles/STBService/Components_HDMI.cpp \ + ../../../profiles/STBService/Components_AudioOutput.cpp \ + ../../../profiles/STBService/Components_VideoDecoder.cpp \ + ../../../profiles/STBService/Components_SPDIF.cpp \ + ../../../profiles/STBService/Capabilities.cpp \ + ../../../profiles/STBService/Components_DisplayDevice.cpp \ + ../../../handlers/src/x_rdk_req_handler.cpp \ + ../../../profiles/Device/x_rdk_profile.cpp \ + ../../../handlers/src/hostIf_XrdkCentralT2_ReqHandler.cpp \ + ../../../handlers/src/hostIf_rbus_Dml_Provider.cpp + +parodus_CPPFLAGS = -I../ -I../../../../unittest/stubs/ -I/usr/local/include/wrp-c/ -I../../waldb/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include/wdmp-c/ -I/usr/local/include/rbus -I../../../include/ -I../../../../unittest/stubs/ -I../../../handlers/src/ -I/usr/local/include/cjson/ -I/usr/local/include/libparodus/ -I./ -I../../waldb/ -I../../../handlers/include/ -I../../../profiles/Time/ -I../../../profiles/DeviceInfo/ -I../../../profiles/Device -I../../../handlers/include/ -I../../../../unittest/stubs/ds -I../../../profiles/Ethernet/ -I../../../include/ -I../../../profiles/IP/ -I../../../profiles/STBService/ -I/usr/rdk-halif-device_settings/include/ -I/usr/rdkvhal-devicesettings-raspberrypi4/ -DUSE_REMOTE_DEBUGGER -I/usr/remote_debugger/src/ + +parodus_LDADD = -llibparodus -lrdkloggers -lwdmp-c -lwrp-c -lmsgpackc -lprocps -ltrower-base64 -lcimplog -lsoup-3.0 -lcjson -lpthread -lglib-2.0 -lnanomsg -lrbus -lIARMBus -lyajl -lds -ldshalcli -ldbus-1 -lsecure_wrapper -lcurl -L../../waldb/.libs/ -l:libwaldb.a -L../../../profiles/Time/.libs/ -l:libhostIfTime.a -ltinyxml2 -lIARMBus + diff --git a/src/hostif/parodusClient/pal/mock-parodus/configure.ac b/src/hostif/parodusClient/pal/mock-parodus/configure.ac new file mode 100644 index 000000000..d4987e75b --- /dev/null +++ b/src/hostif/parodusClient/pal/mock-parodus/configure.ac @@ -0,0 +1,6 @@ +AC_INIT([mock_parodus_for_t2], [1.0], [your_email@example.com]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) +AC_PROG_CC +AC_PROG_CXX +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/src/hostif/parodusClient/pal/mock-parodus/mock_parodus_build.sh b/src/hostif/parodusClient/pal/mock-parodus/mock_parodus_build.sh new file mode 100644 index 000000000..b018aec1d --- /dev/null +++ b/src/hostif/parodusClient/pal/mock-parodus/mock_parodus_build.sh @@ -0,0 +1,3 @@ +sed -i '/getCurrentTime/,/^ *}/d' ../../../src/hostIf_utils.cpp +autoreconf --install && \ +./configure --prefix=/usr/local && make && make install diff --git a/src/hostif/parodusClient/pal/mock-parodus/parodus.cpp b/src/hostif/parodusClient/pal/mock-parodus/parodus.cpp new file mode 100644 index 000000000..a12e7e8a7 --- /dev/null +++ b/src/hostif/parodusClient/pal/mock-parodus/parodus.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include "webpa_adapter.h" + +int main(int argc, char* argv[]) +{ + + std::cout <<"parodus start" << std::endl; + wrp_msg_t *wrp_msg; + wrp_msg_t *res_wrp_msg ; + + wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t)); + res_wrp_msg = (wrp_msg_t *)malloc(sizeof(wrp_msg_t)); + memset(res_wrp_msg, 0, sizeof(wrp_msg_t)); + + wrp_msg->msg_type = WRP_MSG_TYPE__REQ; + + const char *payload = argv[1]; + wrp_msg->u.req.payload = (void*)payload; + + wrp_msg->u.req.payload_size = strlen((char*)wrp_msg->u.req.payload); + + processRequest((char*)wrp_msg->u.req.payload, (char*)wrp_msg->u.req.transaction_uuid, ((char **)(&(res_wrp_msg->u.req.payload)))); + + std::cout << "Response payload: " << (char*)res_wrp_msg->u.req.payload << std::endl; + + char *json_response = (char*)res_wrp_msg->u.req.payload; + if (json_response && json_response[0] != '\0') + { + std::ofstream logFile("/opt/logs/parodus.log"); + + if (logFile.is_open()) { + + logFile << "Response payload: " << json_response << std::endl; + logFile.close(); + } else { + std::cerr << "Failed to open parodus log file" << std::endl; + } + + } else { + std::cout << "Response is empty, not writing to parodus.log" << std::endl; + } + + std::cout << "parodus end"<< std::endl; +} diff --git a/src/hostif/parodusClient/pal/webpa_adapter.cpp b/src/hostif/parodusClient/pal/webpa_adapter.cpp index 0fb13a991..6919db527 100644 --- a/src/hostif/parodusClient/pal/webpa_adapter.cpp +++ b/src/hostif/parodusClient/pal/webpa_adapter.cpp @@ -501,3 +501,15 @@ void getCurrentTime(struct timespec *timer) { clock_gettime(CLOCK_REALTIME, timer); } + +#ifdef GTEST_ENABLE +WDMP_STATUS (*validate_parameterFunc()) (param_t *param, int paramCount) +{ + return &validate_parameter; +} + +void (*setRebootReasonFunc()) (param_t param, WEBPA_SET_TYPE setType) +{ + return &setRebootReason; +} +#endif diff --git a/src/hostif/parodusClient/pal/webpa_adapter.h b/src/hostif/parodusClient/pal/webpa_adapter.h index 1b373587e..ab07ee5e3 100644 --- a/src/hostif/parodusClient/pal/webpa_adapter.h +++ b/src/hostif/parodusClient/pal/webpa_adapter.h @@ -50,7 +50,7 @@ #define LOG_PARODUS_IF "LOG.RDK.PARODUSIF" #define WAL_FREE(__x__) if(__x__ != NULL) { free((void*)(__x__)); __x__ = NULL;} -#define MAX_PARAMETER_LEN 512 +#define MAX_PARAMETER_LEN 512 #define RDKC_XPC_SYNC_PARAM_CID #define MAX_PARAMETERNAME_LEN 256 @@ -341,5 +341,9 @@ WAL_STATUS sendIoTMessage(const void *msg); void getCurrentTime(struct timespec *timer); +#ifdef GTEST_ENABLE +void notificationCallBack(); +#endif + #endif /* _WEBPA_ADAPTER_H_ */ diff --git a/src/hostif/parodusClient/pal/webpa_attribute.cpp b/src/hostif/parodusClient/pal/webpa_attribute.cpp index 123d41b16..73fa2681c 100644 --- a/src/hostif/parodusClient/pal/webpa_attribute.cpp +++ b/src/hostif/parodusClient/pal/webpa_attribute.cpp @@ -227,3 +227,27 @@ static WAL_STATUS setParamAttributes(const char *pParameterName, const AttrVal * ret = set_AttribValues_tr69hostIf (&Param); return ret; } + +#ifdef GTEST_ENABLE +WAL_STATUS (*get_AttribValues_tr69hostIfFunc()) (HOSTIF_MsgData_t *ptrParam) +{ + return &get_AttribValues_tr69hostIf; +} + +WAL_STATUS (*set_AttribValues_tr69hostIfFunc()) (HOSTIF_MsgData_t *param) +{ + return &set_AttribValues_tr69hostIf; +} + +WAL_STATUS (*getParamAttributesFunc()) (const char *pParameterName, AttrVal ***attr, int *TotalParams) +{ + return &getParamAttributes; +} + +WAL_STATUS (*setParamAttributesFunc()) (const char *pParameterName, const AttrVal *attArr) +{ + return &setParamAttributes; +} + + +#endif diff --git a/src/hostif/parodusClient/pal/webpa_notification.cpp b/src/hostif/parodusClient/pal/webpa_notification.cpp index 473e0199b..81f52f0e4 100644 --- a/src/hostif/parodusClient/pal/webpa_notification.cpp +++ b/src/hostif/parodusClient/pal/webpa_notification.cpp @@ -249,3 +249,10 @@ int getnotifyparamList(char ***notifyParamList,int *ptrnotifyListSize) } return 0; } + +#ifdef GTEST_ENABLE +void (*macToLowerFunc())(char macValue[],char macConverted[]) +{ + return &macToLower; +} +#endif diff --git a/src/hostif/parodusClient/pal/webpa_parameter.cpp b/src/hostif/parodusClient/pal/webpa_parameter.cpp index 7d9856225..9ef5b0987 100644 --- a/src/hostif/parodusClient/pal/webpa_parameter.cpp +++ b/src/hostif/parodusClient/pal/webpa_parameter.cpp @@ -38,7 +38,7 @@ /* Function Prototypes */ /*----------------------------------------------------------------------------*/ static WDMP_STATUS GetParamInfo (const char *pParameterName, param_t ***parametervalPtrPtr, int *paramCountPtr,int paramIndex); -static WDMP_STATUS get_ParamValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam); +static WDMP_STATUS get_ParamValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam, DataModelParam *dmParam); int isWildCardParam(const char *paramName); static void converttohostIfType(char *ParamDataType,HostIf_ParamType_t* pParamType); static void converttoWalType(HostIf_ParamType_t paramType,WAL_DATA_TYPE* pwalType); @@ -358,7 +358,7 @@ static WDMP_STATUS GetParamInfo (const char *pParameterName, param_t ***paramete (*parametervalPtrPtr)[index][wc_cnt].value = NULL; // Convert Param.paramtype to ParamVal.type - getRet = get_ParamValues_tr69hostIf (&Param); + getRet = get_ParamValues_tr69hostIf (&Param, NULL); // Fill Only if we can able to get Proper value if(WDMP_SUCCESS == getRet) { @@ -439,9 +439,9 @@ static WDMP_STATUS GetParamInfo (const char *pParameterName, param_t ***paramete { converttohostIfType (dmParam.dataType, &(Param.paramtype)); //CID:18170 - FORWARD NULL } - freeDataModelParam(dmParam); Param.instanceNum = 0; - ret = get_ParamValues_tr69hostIf (&Param); + ret = get_ParamValues_tr69hostIf (&Param, &dmParam); + freeDataModelParam(dmParam); if (ret == WDMP_SUCCESS) { int iParamValSize = MAX_PARAM_LENGTH; @@ -652,7 +652,7 @@ static WAL_STATUS SetParamInfo(ParamVal paramVal, char * transactionID) /** * generic Api for get HostIf parameters **/ -static WDMP_STATUS get_ParamValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam) +static WDMP_STATUS get_ParamValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam, DataModelParam *dmParam) { int status = -1; ptrParam->reqType = HOSTIF_GET; @@ -660,6 +660,14 @@ static WDMP_STATUS get_ParamValues_tr69hostIf(HOSTIF_MsgData_t *ptrParam) status = hostIf_GetMsgHandler(ptrParam); if(status != 0) { + if (dmParam != NULL && dmParam->defaultValue) + { + strncpy(ptrParam->paramValue, dmParam->defaultValue, MAX_PARAM_LENGTH - 1); + ptrParam->paramValue[MAX_PARAM_LENGTH - 1] = '\0'; + paramValueToString(ptrParam, ptrParam->paramValue, sizeof(ptrParam->paramValue)); + status = WDMP_ERR_DEFAULT_VALUE; + return WDMP_SUCCESS; + } RDK_LOG(RDK_LOG_ERROR,LOG_PARODUS_IF,"[%s:%s:%d] Error in Get Message Handler : %d\n", __FILE__, __FUNCTION__, __LINE__, status); retStatus =(WDMP_STATUS) convertFaultCodeToWalStatus(ptrParam->faultCode); // returning appropriate fault code for get RDK_LOG(RDK_LOG_DEBUG,LOG_PARODUS_IF,"[%s:%d] return status of fault code: %d\n", __FUNCTION__, __LINE__, retStatus); @@ -788,3 +796,59 @@ static void converttoWalType(HostIf_ParamType_t paramType,WAL_DATA_TYPE* pwalTyp } } +#ifdef GTEST_ENABLE +WDMP_STATUS (*GetParamInfoFunc()) (const char *pParameterName, param_t ***parametervalPtrPtr, int *paramCountPtr,int paramIndex) +{ + return &GetParamInfo; +} + +rbusValueType_t (*getRbusDataTypefromWebPAFunc())(WAL_DATA_TYPE type) +{ + return &getRbusDataTypefromWebPA; +} + +DATA_TYPE (*mapRbusDataTypeToWebPAFunc()) (rbusValueType_t type) +{ + return &mapRbusDataTypeToWebPA; +} + +WDMP_STATUS (*get_ParamValues_tr69hostIfFunc()) (HOSTIF_MsgData_t *ptrParam, DataModelParam *dmParam) +{ + return &get_ParamValues_tr69hostIf; +} + +WAL_STATUS (*set_ParamValues_tr69hostIfFunc()) (HOSTIF_MsgData_t *ptrParam) +{ + return &set_ParamValues_tr69hostIf; +} + +WAL_STATUS (*convertFaultCodeToWalStatusFunc())(faultCode_t faultCode) +{ + return &convertFaultCodeToWalStatus; +} + +void (*converttohostIfTypeFunc())(char *ParamDataType,HostIf_ParamType_t* pParamType) +{ + return &converttohostIfType; +} + +void (*converttoWalTypeFunc())(HostIf_ParamType_t paramType,WAL_DATA_TYPE* pwalType) +{ + return &converttoWalType; +} + +WDMP_STATUS (*rbusGetParamInfoFunc()) (const char *pParameterName, param_t ***parametervalPtrPtr, int *paramCountPtr, int index) +{ + return &rbusGetParamInfo; +} + +WAL_STATUS (*rbusSetParamInfoFunc()) (ParamVal paramVal, char * transactionID) +{ + return &rbusSetParamInfo; +} + +WAL_STATUS (*SetParamInfoFunc()) (ParamVal paramVal, char * transactionID) +{ + return &SetParamInfo; +} +#endif diff --git a/src/hostif/parodusClient/pal/webpa_parameter.h b/src/hostif/parodusClient/pal/webpa_parameter.h index 995557875..32644d570 100644 --- a/src/hostif/parodusClient/pal/webpa_parameter.h +++ b/src/hostif/parodusClient/pal/webpa_parameter.h @@ -37,7 +37,7 @@ extern "C" #define MAX_NUM_PARAMETERS 2048 #define MAX_DATATYPE_LENGTH 48 #define MAX_PARAM_LENGTH TR69HOSTIFMGR_MAX_PARAM_LEN -#define MAX_PARAMETER_LENGTH 512 +#define MAX_PARAMETER_LENGTH 512 #define MAX_PARAMETERVALUE_LEN 128 diff --git a/src/hostif/parodusClient/parodus.service b/src/hostif/parodusClient/parodus.service index 5d1b8acbe..69b587353 100644 --- a/src/hostif/parodusClient/parodus.service +++ b/src/hostif/parodusClient/parodus.service @@ -28,7 +28,7 @@ SyslogIdentifier="parodus" EnvironmentFile=/etc/device.properties Type=forking PIDFile=/run/parodus.pid -ExecStart=/usr/bin/startParodusMain +ExecStart=/bin/sh -c '/usr/bin/startParodusMain' ExecStop=/bin/kill -2 $MAINPID RestartSec=40s Restart=always diff --git a/src/hostif/parodusClient/startParodus/startParodus.cpp b/src/hostif/parodusClient/startParodus/startParodus.cpp index 558d1ce97..cf9c43498 100644 --- a/src/hostif/parodusClient/startParodus/startParodus.cpp +++ b/src/hostif/parodusClient/startParodus/startParodus.cpp @@ -29,6 +29,7 @@ #include "cJSON.h" #include "rfcapi.h" #include "hostIf_utils.h" +//#include "rdk_debug.h" #include "secure_wrapper.h" #include #include @@ -37,7 +38,7 @@ #define WEBPA_CFG_FILE "/etc/webpa_cfg.json" #define WEBPA_CFG_OVERIDE_FILE "/opt/webpa_cfg.json" -#define CRUD_CONFIG_FILE "/opt/parodus_cfg.json" +#define CRUD_CONFIG_FILE "/opt/secure/parodus_cfg.json" #define SSL_CERT_FILE "/etc/ssl/certs/ca-certificates.crt" #define JWT_KEY "/etc/ssl/certs/webpa-rs256.pem" #define RECORD_JWT_PAYLOAD_FILE "/tmp/xmidt-jwt-payload.json" @@ -53,6 +54,7 @@ #define PARTNERID "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId" #define UNKNOWN_PARTNERID "unknown" #define PARTNERID_APPEND "*," +#define MAX_PARTNER_ID_SIZE 128 #ifndef CONFIG_RES_FILE // please update with the orginal value based on your device #define CONFIG_RES_FILE "/tmp/data" @@ -79,7 +81,8 @@ std::string get_HWMAcAddress() fp = fopen(HWMAC_FILE, "r"); if (fp != NULL) { - fread(tempMAC, 1, 17, fp); + size_t bytesRead = fread(tempMAC, 1, 17, fp); + printf("The value of bytes read: %zu\n", bytesRead); fclose(fp); for (srcCount = 0; dstCount < 12 && srcCount < 17; srcCount++) { @@ -96,7 +99,6 @@ std::string get_HWMAcAddress() } return hwAddr; } - std::string get_PartnerId() { char PartnerId[128] = ""; @@ -104,30 +106,41 @@ std::string get_PartnerId() FILE *fp = NULL; int ch_count = 0; std::string partnerId = ""; - struct stat status; + int fd; RFC_ParamData_t param = {0}; - // use partner-id from auth service to start parodus - if ((stat(PARTNERID_FILE, &status) == 0)) + fd = open(PARTNERID_FILE, O_RDONLY); + if (fd != -1) { - fp = fopen(PARTNERID_FILE, "r"); - fseek(fp, 0, SEEK_END); - ch_count = ftell(fp); - if (ch_count < 1) - { - printf("Partner ID file is Empty %s\n", PARTNERID_FILE); - fclose(fp); - } - else + fp = fdopen(fd, "r"); + if (fp != NULL) { - fseek(fp, 0, SEEK_SET); - fread(PartnerId, 1, ch_count, fp); - fclose(fp); - fp = NULL; - partnerId = PartnerId; - printf("[%s:%d]PARTNERID = [ %s ] \n", __FUNCTION__, __LINE__, PartnerId); + fseek(fp, 0, SEEK_END); + ch_count = ftell(fp); + if (ch_count < 1) + { + printf("Partner ID file is Empty %s\n", PARTNERID_FILE); + fclose(fp); + } + else + { + fseek(fp, 0, SEEK_SET); + size_t bytesRead = fread(PartnerId, 1, ch_count, fp); + if (bytesRead != (size_t)ch_count) + { + printf("Error reading Partner ID, bytes read: %zu\n", bytesRead); + fclose(fp); + return partnerId; + } + PartnerId[ch_count] = '\0'; + fclose(fp); + fp = NULL; + partnerId = PartnerId; + printf("[%s:%d]PARTNERID = [ %s ] \n", __FUNCTION__, __LINE__, PartnerId); + } } - } + close(fd); + } else { getRFCParameter((char *)"webcfg", PARTNERID, ¶m); @@ -136,8 +149,10 @@ std::string get_PartnerId() { printf("[%s:%d]PARTNERID RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); // remove quotes arround data - strncpy(PartnerId, ¶m.value[0], dataLen); - PartnerId[dataLen] = '\0'; + strncpy(PartnerId, ¶m.value[0], sizeof(PartnerId) - 1); + PartnerId[sizeof(PartnerId) - 1] = '\0'; + + } } if (!strncmp(PartnerId, UNKNOWN_PARTNERID, sizeof(UNKNOWN_PARTNERID))) @@ -163,51 +178,62 @@ std::string get_RebootReason() FILE *fp = NULL; int ch_count = 0; std::string reboot_reason = ""; - struct stat status; + int fd; - if ((stat(REBOOT_REASON_SECURE_FILE, &status) == 0)) - fp = fopen(REBOOT_REASON_SECURE_FILE, "r"); - if (fp != NULL) + fd = open(REBOOT_REASON_SECURE_FILE, O_RDONLY); + if (fd != -1) { - fseek(fp, 0, SEEK_END); - ch_count = ftell(fp); - if (ch_count < 1) + fp = fdopen(fd, "r"); + if (fp != NULL) { - printf("Reboot reason file is Empty %s\n", REBOOT_REASON_SECURE_FILE); - fclose(fp); - } - else - { - fseek(fp, 0, SEEK_SET); - rebootReasonFile = (char *)malloc(sizeof(char) * (ch_count + 1)); - if (rebootReasonFile) - { - fread(rebootReasonFile, 1, ch_count, fp); - rebootReasonFile[ch_count] = '\0'; - fclose(fp); - fp = NULL; - - // CID:18143 - NEGATIVE RETURNS - since ch_count cannot be negative - cJSON *rebootFile = cJSON_Parse(rebootReasonFile); - if (rebootFile) - { - cJSON *reason = NULL; - - reason = cJSON_GetObjectItem(rebootFile, "reason"); - if ((NULL != reason && NULL != reason->valuestring)) - { - reboot_reason = reason->valuestring; - reboot_reason.erase(std::remove(reboot_reason.begin(), reboot_reason.end(), '\n'), reboot_reason.cend()); - } - } - free(rebootReasonFile); // CID:18606 - Resource leak - } - else - { - fclose(fp); - fp = NULL; + fseek(fp, 0, SEEK_END); + ch_count = ftell(fp); + if (ch_count < 1) + { + printf("Reboot reason file is Empty %s\n", REBOOT_REASON_SECURE_FILE); + fclose(fp); + } + else + { + fseek(fp, 0, SEEK_SET); + rebootReasonFile = (char *)malloc(sizeof(char) * (ch_count + 1)); + if (rebootReasonFile) + { + size_t bytesRead = fread(rebootReasonFile, 1, ch_count, fp); + if (bytesRead != (size_t)ch_count) + { + printf("Error reading file, bytes read: %zu\n", bytesRead); + free(rebootReasonFile); + fclose(fp); + return reboot_reason; + } + rebootReasonFile[ch_count] = '\0'; + fclose(fp); + fp = NULL; + + // CID:18143 - NEGATIVE RETURNS - since ch_count cannot be negative + cJSON *rebootFile = cJSON_Parse(rebootReasonFile); + if (rebootFile) + { + cJSON *reason = NULL; + + reason = cJSON_GetObjectItem(rebootFile, "reason"); + if ((NULL != reason && NULL != reason->valuestring)) + { + reboot_reason = reason->valuestring; + reboot_reason.erase(std::remove(reboot_reason.begin(), reboot_reason.end(), '\n'), reboot_reason.cend()); + } + } + free(rebootReasonFile); // CID:18606 - Resource leak + } + else + { + fclose(fp); + fp = NULL; + } } } + close(fd); } else { @@ -228,7 +254,13 @@ std::string get_FwName() fgets(line, 128, fp); token = strtok(line, ":"); token = strtok(NULL, ":"); - strncpy(imageName, token, strlen(token)); + if (token != NULL) { + snprintf(imageName, sizeof(imageName), "%s", token); + } + else { + // Handle the null case if necessary + printf("Error: Token is null\n"); + } fclose(fp); fp = NULL; fw_name = imageName; @@ -237,228 +269,266 @@ std::string get_FwName() return fw_name; } +#ifndef GTEST_ENABLE int main(int argc, char *argv[]) { - /*Parameter for the parodus client*/ - std::string webpa_url = ""; - std::string partnerId = ""; - char *manufacturer = NULL; - char *model = NULL; - std::string serialNumber = ""; - std::string networkIf = ""; - std::string dnsTextUrl = ""; - std::string tokenServerUrl = ""; - std::string bootTime = ""; - std::string clientCertFile = ""; - int acquireJWT = 0; - int serverPort = 0; - int pingWaitTime = 0; - struct stat status; - FILE *fp = NULL; - int ch_count = 0; - char *webpaCfgFile = NULL; - RFC_ParamData_t param = {0}; - int dataLen = 0; - - // parodus_Gloop = g_main_loop_new(NULL, FALSE); - - signal(SIGTERM, processExit); - signal(SIGKILL, processExit); - signal(SIGABRT, processExit); - - // Get the server IP from RFC parameter - getRFCParameter((char *)"webcfg", SERVER_IP_URL, ¶m); - dataLen = strlen(param.value); - if (dataLen != 0) - { - printf("[%s:%d]SERVER_IP_URL RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); - webpa_url = param.value; - } - - // Get the data from Configuration file - if ((stat(WEBPA_CFG_OVERIDE_FILE, &status) == 0)) - { - fp = fopen(WEBPA_CFG_OVERIDE_FILE, "r"); - } - else - { - fp = fopen(WEBPA_CFG_FILE, "r"); - } - - if (fp != NULL) - { - fseek(fp, 0, SEEK_END); - ch_count = ftell(fp); + try + { + /*Parameter for the parodus client*/ + std::string webpa_url = ""; + std::string partnerId = ""; + char *manufacturer = NULL; + char *model = NULL; + std::string serialNumber = ""; + std::string networkIf = ""; + std::string dnsTextUrl = ""; + std::string tokenServerUrl = ""; + std::string bootTime = ""; + std::string clientCertFile = ""; + int acquireJWT = 0; + int serverPort = 0; + int pingWaitTime = 0; + struct stat status; + FILE *fp = NULL; + int ch_count = 0; + char *webpaCfgFile = NULL; + RFC_ParamData_t param = {0}; + int dataLen = 0; + + // parodus_Gloop = g_main_loop_new(NULL, FALSE); + + signal(SIGTERM, processExit); + signal(SIGKILL, processExit); + signal(SIGABRT, processExit); + + // Get the server IP from RFC parameter + getRFCParameter((char *)"webcfg", SERVER_IP_URL, ¶m); + dataLen = strlen(param.value); + if (dataLen != 0) + { + printf("[%s:%d]SERVER_IP_URL RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); + webpa_url = param.value; + } - if (ch_count < 1) + // Get the data from Configuration file + int fd = open(WEBPA_CFG_OVERIDE_FILE, O_RDONLY); + if (fd != -1) { - printf("WebPA config file is Empty %s\n", WEBPA_CFG_FILE); - fclose(fp); + fp = fdopen(fd, "r"); } else { - fseek(fp, 0, SEEK_SET); - webpaCfgFile = (char *)malloc(sizeof(char) * (ch_count + 1)); - - if (webpaCfgFile) + fd = open(WEBPA_CFG_FILE, O_RDONLY); + if (fd != -1) { - fread(webpaCfgFile, 1, ch_count, fp); - webpaCfgFile[ch_count] = '\0'; - // CID:18143 - NEGATIVE RETURNS - since ch_count cannot be negative - cJSON *webpa_cfg = cJSON_Parse(webpaCfgFile); - if (webpa_cfg) - { - cJSON *serverIp = NULL; - cJSON *aJwt = NULL; - cJSON *DeviceNwkIf = NULL; - cJSON *srvrPort = NULL; - cJSON *MaxPingWaitTimeInSec = NULL; - - serverIp = cJSON_GetObjectItem(webpa_cfg, "ServerIP"); - aJwt = cJSON_GetObjectItem(webpa_cfg, "acquire-jwt"); - DeviceNwkIf = cJSON_GetObjectItem(webpa_cfg, "DeviceNetworkInterface"); - srvrPort = cJSON_GetObjectItem(webpa_cfg, "ServerPort"); - MaxPingWaitTimeInSec = cJSON_GetObjectItem(webpa_cfg, "MaxPingWaitTimeInSec"); - - if ((NULL != serverIp && NULL != serverIp->valuestring) && (webpa_url.empty())) - { - // strncpy(ServerIP,serverIp->valuestring,strlen(serverIp->valuestring)); - // printf("[%s:%d]ServerIP = [ %s ] \n", __FUNCTION__, __LINE__, ServerIP); - webpa_url = serverIp->valuestring; - } + fp = fdopen(fd, "r"); + } + } - if ((NULL != aJwt)) - { - acquireJWT = aJwt->valueint; - printf("acquireJWT = [ %d ] \n", acquireJWT); - } + if (fp != NULL) + { + fseek(fp, 0, SEEK_END); + ch_count = ftell(fp); - if ((NULL != DeviceNwkIf && NULL != DeviceNwkIf->valuestring)) - { - networkIf = DeviceNwkIf->valuestring; - printf("NetworkIF = [ %s] \n", networkIf.c_str()); - } + if (ch_count < 1) + { + printf("WebPA config file is Empty %s\n", WEBPA_CFG_FILE); + fclose(fp); + } + else + { + fseek(fp, 0, SEEK_SET); + webpaCfgFile = (char *)malloc(sizeof(char) * (ch_count + 1)); - if ((NULL != srvrPort)) + if (webpaCfgFile) + { + size_t bytesRead = fread(webpaCfgFile, 1, ch_count, fp); + if (bytesRead != static_cast(ch_count)) + { + printf("Error reading WebPA config file, bytes read: %zu\n", bytesRead); + free(webpaCfgFile); + fclose(fp); + close(fd); + return 1; // or handle the error as needed + } + + webpaCfgFile[ch_count] = '\0'; + // CID:18143 - NEGATIVE RETURNS - since ch_count cannot be negative + cJSON *webpa_cfg = cJSON_Parse(webpaCfgFile); + if (webpa_cfg) { - serverPort = srvrPort->valueint; - printf("serverPort = [ %d ] \n", serverPort); + cJSON *serverIp = NULL; + cJSON *aJwt = NULL; + cJSON *DeviceNwkIf = NULL; + cJSON *srvrPort = NULL; + cJSON *MaxPingWaitTimeInSec = NULL; + + serverIp = cJSON_GetObjectItem(webpa_cfg, "ServerIP"); + aJwt = cJSON_GetObjectItem(webpa_cfg, "acquire-jwt"); + DeviceNwkIf = cJSON_GetObjectItem(webpa_cfg, "DeviceNetworkInterface"); + srvrPort = cJSON_GetObjectItem(webpa_cfg, "ServerPort"); + MaxPingWaitTimeInSec = cJSON_GetObjectItem(webpa_cfg, "MaxPingWaitTimeInSec"); + + if ((NULL != serverIp && NULL != serverIp->valuestring) && (webpa_url.empty())) + { + // strncpy(ServerIP,serverIp->valuestring,strlen(serverIp->valuestring)); + // printf("[%s:%d]ServerIP = [ %s ] \n", __FUNCTION__, __LINE__, ServerIP); + webpa_url = serverIp->valuestring; + } + + if ((NULL != aJwt)) + { + acquireJWT = aJwt->valueint; + printf("acquireJWT = [ %d ] \n", acquireJWT); + } + + if ((NULL != DeviceNwkIf && NULL != DeviceNwkIf->valuestring)) + { + networkIf = DeviceNwkIf->valuestring; + printf("NetworkIF = [ %s] \n", networkIf.c_str()); + } + + if ((NULL != srvrPort)) + { + serverPort = srvrPort->valueint; + printf("serverPort = [ %d ] \n", serverPort); + } + + if ((NULL != MaxPingWaitTimeInSec)) + { + pingWaitTime = MaxPingWaitTimeInSec->valueint; + printf("pingWaitTime = [ %d ] \n", pingWaitTime); + } } - - if ((NULL != MaxPingWaitTimeInSec)) + free(webpaCfgFile); // CID:18606 - Resource leak + if (fp) { - pingWaitTime = MaxPingWaitTimeInSec->valueint; - printf("pingWaitTime = [ %d ] \n", pingWaitTime); + fclose(fp); + fp = NULL; } } - free(webpaCfgFile); // CID:18606 - Resource leak - if (fp) + else { fclose(fp); fp = NULL; } } - else - { - fclose(fp); - fp = NULL; - } } - } - else - { - printf("Failed to open Webpa cfg file %s\n", WEBPA_CFG_FILE); - } + else + { + printf("Failed to open Webpa cfg file %s\n", WEBPA_CFG_FILE); + } -#ifdef RDKCLISSA - getDeviceConfigFile(); -#endif + #ifdef RDKCLISSA + getDeviceConfigFile(); + #endif - // Getting Webpa Parameters - // Get "Device.X_RDK_WebPA_DNSText.URL" - getRFCParameter((char *)"webcfg", DNS_TEXT_URL, ¶m); - dataLen = strlen(param.value); - if (dataLen != 0) - { - printf("[%s:%d]DNS_TEXT_URL RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); - dnsTextUrl = param.value; - } + // Getting Webpa Parameters + // Get "Device.X_RDK_WebPA_DNSText.URL" + getRFCParameter((char *)"webcfg", DNS_TEXT_URL, ¶m); + dataLen = strlen(param.value); + if (dataLen != 0) + { + printf("[%s:%d]DNS_TEXT_URL RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); + dnsTextUrl = param.value; + } - // X_RDK_WebPA_TokenServer - getRFCParameter((char *)"webcfg", TOKEN_SERVER_URL, ¶m); - dataLen = strlen(param.value); - if (dataLen != 0) - { - printf("[%s:%d]TOKEN_SERVER_URL RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); - // remove quotes arround data - tokenServerUrl = param.value; - } + // X_RDK_WebPA_TokenServer + getRFCParameter((char *)"webcfg", TOKEN_SERVER_URL, ¶m); + dataLen = strlen(param.value); + if (dataLen != 0) + { + printf("[%s:%d]TOKEN_SERVER_URL RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); + // remove quotes arround data + tokenServerUrl = param.value; + } - // Manufacturer - manufacturer = getenv("MANUFACTURE"); + // Manufacturer + manufacturer = getenv("MANUFACTURE"); - // Model Number - model = getenv("MODEL_NUM"); + // Model Number + model = getenv("MODEL_NUM"); - // Partner ID - partnerId = get_PartnerId(); + // Partner ID + partnerId = get_PartnerId(); - // Reboot reason - std::string reboot_reason = get_RebootReason(); + // Reboot reason + std::string reboot_reason = get_RebootReason(); - /*Get HW MAc Address*/ - std::string hw_addr = get_HWMAcAddress(); + /*Get HW MAc Address*/ + std::string hw_addr = get_HWMAcAddress(); - // Image Name - std::string fw_name = get_FwName(); + // Image Name + std::string fw_name = get_FwName(); - // Serial Number - getRFCParameter((char *)"webcfg", SERIAL_NUMBER, ¶m); - dataLen = strlen(param.value); - if (dataLen != 0) - { - printf("[%s:%d] SERIAL_NUMBER RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); - serialNumber = param.value; - } + // Serial Number + getRFCParameter((char *)"webcfg", SERIAL_NUMBER, ¶m); + dataLen = strlen(param.value); + if (dataLen != 0) + { + printf("[%s:%d] SERIAL_NUMBER RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); + serialNumber = param.value; + } - // get_Boottime - getRFCParameter((char *)"webcfg", BOOT_TIME, ¶m); - dataLen = strlen(param.value); - if (dataLen != 0) - { - printf("[%s:%d]BOOT_TIME RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); - bootTime = param.value; - } + // get_Boottime + getRFCParameter((char *)"webcfg", BOOT_TIME, ¶m); + dataLen = strlen(param.value); + if (dataLen != 0) + { + printf("[%s:%d]BOOT_TIME RFC PARAM VALUE = [ %s ] \n", __FUNCTION__, __LINE__, param.value); + bootTime = param.value; + } - // Config File check - if ((stat(CONFIG_RES_FILE, &status) == 0)) - { - clientCertFile = CONFIG_RES_FILE; - } - // Starting Parodus - printf("Parodus Process satrting with Arguments: = [ /usr/bin/parodus \ - --hw-mac=%s --webpa-ping-time=%d --webpa-interface-used=%s --webpa-url=%s \ - --partner-id=%s --webpa-backoff-max=9 --ssl-cert-path=%s --acquire-jwt=%d \ - --dns-txt-url=%s --jwt-public-key-file=%s --jwt-algo=RS256 --record-jwt-payload=%s \ - --crud-config-file=%s --hw-manufacturer=%s --fw-name=%s --hw-model=%s \ - --hw-serial-number=%s --boot-time=%s --hw-last-reboot-reason=\"%s\" --client-cert-path=%s --token-server-url=%s & ]\n", - hw_addr.c_str(), pingWaitTime, networkIf.c_str(), webpa_url.c_str(), - partnerId.c_str(), SSL_CERT_FILE, acquireJWT, - dnsTextUrl.c_str(), JWT_KEY, RECORD_JWT_PAYLOAD_FILE, - CRUD_CONFIG_FILE, manufacturer, fw_name.c_str(), model, - serialNumber.c_str(), bootTime.c_str(), reboot_reason.c_str(), clientCertFile.c_str(), tokenServerUrl.c_str()); - - v_secure_system("backgroundrun /usr/bin/parodus \ - --hw-mac=%s --webpa-ping-time=%d --webpa-interface-used=%s --webpa-url=%s \ - --partner-id=%s --webpa-backoff-max=9 --ssl-cert-path=%s --acquire-jwt=%d \ - --dns-txt-url=%s --jwt-public-key-file=%s --jwt-algo=RS256 --record-jwt-payload=%s \ - --crud-config-file=%s --hw-manufacturer=%s --fw-name=%s --hw-model=%s \ - --hw-serial-number=%s --boot-time=%s --hw-last-reboot-reason=\"%s\" --client-cert-path=%s --token-server-url=%s", - hw_addr.c_str(), pingWaitTime, networkIf.c_str(), webpa_url.c_str(), - partnerId.c_str(), SSL_CERT_FILE, acquireJWT, - dnsTextUrl.c_str(), JWT_KEY, RECORD_JWT_PAYLOAD_FILE, - CRUD_CONFIG_FILE, manufacturer, fw_name.c_str(), model, - serialNumber.c_str(), bootTime.c_str(), reboot_reason.c_str(), clientCertFile.c_str(), tokenServerUrl.c_str()); - - return 0; + // Config File check + if ((stat(CONFIG_RES_FILE, &status) == 0)) + { + clientCertFile = CONFIG_RES_FILE; + } + // Starting Parodus + printf("Parodus Process satrting with Arguments: = [ /usr/bin/parodus \ + --hw-mac=%s --webpa-ping-time=%d --webpa-interface-used=%s --webpa-url=%s \ + --partner-id=%s --webpa-backoff-max=9 --ssl-cert-path=%s --acquire-jwt=%d \ + --dns-txt-url=%s --jwt-public-key-file=%s --jwt-algo=RS256 --record-jwt-payload=%s \ + --crud-config-file=%s --hw-manufacturer=%s --fw-name=%s --hw-model=%s \ + --hw-serial-number=%s --boot-time=%s --hw-last-reboot-reason=\"%s\" --client-cert-path=%s --token-server-url=%s & ]\n", + hw_addr.c_str(), pingWaitTime, networkIf.c_str(), webpa_url.c_str(), + partnerId.c_str(), SSL_CERT_FILE, acquireJWT, + dnsTextUrl.c_str(), JWT_KEY, RECORD_JWT_PAYLOAD_FILE, + CRUD_CONFIG_FILE, manufacturer, fw_name.c_str(), model, + serialNumber.c_str(), bootTime.c_str(), reboot_reason.c_str(), clientCertFile.c_str(), tokenServerUrl.c_str()); + + v_secure_system("backgroundrun /usr/bin/parodus \ + --hw-mac=%s --webpa-ping-time=%d --webpa-interface-used=%s --webpa-url=%s \ + --partner-id=%s --webpa-backoff-max=9 --ssl-cert-path=%s --acquire-jwt=%d \ + --dns-txt-url=%s --jwt-public-key-file=%s --jwt-algo=RS256 --record-jwt-payload=%s \ + --crud-config-file=%s --hw-manufacturer=%s --fw-name=%s --hw-model=%s \ + --hw-serial-number=%s --boot-time=%s --hw-last-reboot-reason=\"%s\" --client-cert-path=%s --token-server-url=%s", + hw_addr.c_str(), pingWaitTime, networkIf.c_str(), webpa_url.c_str(), + partnerId.c_str(), SSL_CERT_FILE, acquireJWT, + dnsTextUrl.c_str(), JWT_KEY, RECORD_JWT_PAYLOAD_FILE, + CRUD_CONFIG_FILE, manufacturer, fw_name.c_str(), model, + serialNumber.c_str(), bootTime.c_str(), reboot_reason.c_str(), clientCertFile.c_str(), tokenServerUrl.c_str()); + + + } + catch (const std::bad_cast& e) + { + std::cerr << "Bad cast exception: " << e.what() << std::endl; + return 1; + } + catch (const std::exception& e) + { + std::cerr << "Exception: " << e.what() << std::endl; + return 1; + } + catch (...) + { + std::cerr << "Unknown exception occurred" << std::endl; + return 1; + } + + + +return 0; } +#endif diff --git a/src/hostif/parodusClient/startParodus/startParodus.h b/src/hostif/parodusClient/startParodus/startParodus.h new file mode 100644 index 000000000..d38243578 --- /dev/null +++ b/src/hostif/parodusClient/startParodus/startParodus.h @@ -0,0 +1,35 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +#ifndef STARTPARODUS_H_ +#define STARTPARODUS_H_ + +#include +#include + +#if defined(GTEST_ENABLE) +std::string get_HWMAcAddress(); + +std::string get_PartnerId(); + +std::string get_RebootReason(); + +std::string get_FwName(); +#endif + +#endif /* STARTPARODUS_H_ */ diff --git a/src/hostif/parodusClient/waldb/data-model-generic.xml b/src/hostif/parodusClient/waldb/data-model-generic.xml new file mode 100644 index 000000000..8813aefe1 --- /dev/null +++ b/src/hostif/parodusClient/waldb/data-model-generic.xml @@ -0,0 +1,487 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/hostif/parodusClient/waldb/data-model/data-model-generic.xml b/src/hostif/parodusClient/waldb/data-model/data-model-generic.xml index 563a17d8f..fd6eefa85 100755 --- a/src/hostif/parodusClient/waldb/data-model/data-model-generic.xml +++ b/src/hostif/parodusClient/waldb/data-model/data-model-generic.xml @@ -85,6 +85,18 @@ + + + + + + + + + + + + @@ -224,13 +236,13 @@ - + - + @@ -335,6 +347,14 @@ + + + + + + + + @@ -511,6 +531,14 @@ + + + + + + + + @@ -3179,6 +3207,11 @@ + + + + + @@ -3509,21 +3542,6 @@ - - - - - - - - - - - - - - - @@ -3538,6 +3556,11 @@ + + + + + @@ -3549,18 +3572,30 @@ - - + + - + + + + + + + + + + + + + @@ -4037,7 +4072,8 @@ - + + @@ -4075,6 +4111,14 @@ + + + + + + + + @@ -4094,14 +4138,6 @@ - - - - - - - - @@ -4281,7 +4317,7 @@ - + @@ -4308,14 +4344,6 @@ - - - - - - - - @@ -4344,13 +4372,21 @@ - + + + + + + + + + @@ -4390,5 +4426,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/hostif/parodusClient/waldb/data-model/data-model-stb.xml b/src/hostif/parodusClient/waldb/data-model/data-model-stb.xml index 6ab3a6bf8..6bd0f590e 100755 --- a/src/hostif/parodusClient/waldb/data-model/data-model-stb.xml +++ b/src/hostif/parodusClient/waldb/data-model/data-model-stb.xml @@ -40,11 +40,6 @@ - - - - - @@ -461,6 +456,14 @@ + + + + + + + + @@ -468,5 +471,13 @@ + + + + + + + + diff --git a/src/hostif/parodusClient/waldb/data-model/data-model-tv.xml b/src/hostif/parodusClient/waldb/data-model/data-model-tv.xml index 96c2790d9..9c0316f2c 100644 --- a/src/hostif/parodusClient/waldb/data-model/data-model-tv.xml +++ b/src/hostif/parodusClient/waldb/data-model/data-model-tv.xml @@ -40,11 +40,6 @@ - - - - - @@ -367,6 +362,14 @@ + + + + + + + + @@ -469,5 +472,13 @@ + + + + + + + + diff --git a/src/hostif/parodusClient/waldb/waldb.cpp b/src/hostif/parodusClient/waldb/waldb.cpp index 89fb44e27..0faafe29f 100644 --- a/src/hostif/parodusClient/waldb/waldb.cpp +++ b/src/hostif/parodusClient/waldb/waldb.cpp @@ -31,7 +31,7 @@ #include "safec_lib.h" using namespace tinyxml2; -#define MAX_PARAMETER_LENGTH 512 +#define MAX_PARAMETER_LENGTH 512 #define MAX_DATATYPE_LENGTH 48 #define MAX_NUM_PARAMETERS 2048 #define INSTANCE_NUMBER_INDICATOR "{i}." @@ -405,6 +405,7 @@ void appendNextObject(char* currentParam, const char* pAttparam) // TO DO: Since the size of the destination buffer is not predictable using strcpy strcpy(currentParam, pAttparam); } + /** * @brief Get the list of parameters which is matching with paramName * @@ -538,7 +539,7 @@ static XMLNode* getList(XMLNode *pParent,char *paramName,char* currentParam,char sChild = getList(pChild,tparaName,currentParam,ptrParamList,pParamDataTypeList,paramCount); //TO DO:Since curretParam size is not predictable using strcpy strcpy(currentParam+len, INSTANCE_NUMBER_INDICATOR); - i++; + i++; } pChild = sChild; // Seems like instance count is empty @@ -603,7 +604,8 @@ DB_STATUS getChildParamNamesFromDataModel(void *dbhandle,char *paramName,char ** { char parameterName[MAX_PARAMETER_LENGTH]; char currentParam[MAX_PARAMETER_LENGTH] = "\0"; - strncpy(parameterName,paramName,MAX_PARAMETER_LENGTH-1); + strncpy(parameterName, paramName, MAX_PARAMETER_LENGTH-1); + parameterName[MAX_PARAMETER_LENGTH-1] = '\0'; // Ensure null termination if(dbhandle == NULL) return DB_FAILURE; @@ -956,7 +958,6 @@ static DB_STATUS get_complete_parameter_list_from_dml_xml ( { appendNextObject(currentParam, pAttrib->Value()); std::string str = pAttrib->Value(); - if (str.compare(str.size()-5,5,".{i}.") == 0) { if(params_count < MAX_NUM_PARAMETERS) { diff --git a/src/hostif/parodusClient/waldb/waldb.h b/src/hostif/parodusClient/waldb/waldb.h index 650df8907..94cd823ac 100644 --- a/src/hostif/parodusClient/waldb/waldb.h +++ b/src/hostif/parodusClient/waldb/waldb.h @@ -84,6 +84,17 @@ DB_STATUS getChildParamNamesFromDataModel(void *dbhandle,char *paramName,char ** int getParamInfoFromDataModel(void *handle,const char *paramName,DataModelParam *dmParam); DB_STATUS get_complete_param_list (char **out_param_list, int *out_param_count); + +#if defined(GTEST_ENABLE) +int isParamEndsWithInstance(const char* paramName); +int getNumberOfDigitsInInstanceNumber(const char* paramName,int position); +int getNumberofInstances(const char* paramName); +int checkMatchingParameter(const char* attrValue, char* paramName, int* ret); +void replaceWithInstanceNumber(char *paramName, int instanceNumber); +void appendNextObject(char* currentParam, const char* pAttparam); +void test_get_complete_param_list(); +#endif + #ifdef __cplusplus } #endif diff --git a/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.cpp b/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.cpp index a7934f5bd..edab25485 100644 --- a/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.cpp +++ b/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.cpp @@ -306,6 +306,7 @@ int hostIf_DHCPv4Client::get_Device_DHCPv4_Client_Fields(DHCPv4ClientMembers dhc GList *devList =NULL; GList *elem=NULL; HOSTIF_MsgData_t msgData; + char cmd[MAX_CMD_LEN]; memset(&msgData, 0, sizeof(msgData)); ret=getInterfaceName(ifname); @@ -373,7 +374,7 @@ int hostIf_DHCPv4Client::get_Device_DHCPv4_Client_Fields(DHCPv4ClientMembers dhc break; case eDHCPv4Iprouters: memset(dhcpClient.ipRouters, '\0', sizeof(dhcpClient.ipRouters)); - memset(cmd, 0, sizeof cmd); + memset(cmd, 0, sizeof(cmd)); /*Get the default interface name and its gateway. If the interface name matches with the class interface, then fill iprouters */ cmdOP=v_secure_popen("r", "ip r|grep default| grep %s |awk '{printf $3}'",ifname); if (cmdOP) diff --git a/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.h b/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.h index ecde30575..4edf4d995 100644 --- a/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.h +++ b/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.h @@ -106,6 +106,10 @@ #include "hostIf_utils.h" #include "hostIf_updateHandler.h" +#if defined(GTEST_ENABLE) +#include +#endif + #define MAX_IF_LEN 256 //Length of interface. http://www.broadband-forum.org/cwmp/tr-181-2-8-0.html#D.Device:2.Device.DHCPv4.Client.{i}.Interface #define MAX_DNS_SERVER_LEN 256 //Length of DNS servers. http://www.broadband-forum.org/cwmp/tr-181-2-8-0.html#D.Device:2.Device.DHCPv4.Client.{i}.DNSServers #define MAX_IP_ROUTER_LEN 256 //Length of IP Routers. http://www.broadband-forum.org/cwmp/tr-181-2-8-0.html#D.Device:2.Device.DHCPv4.Client.{i}.IPRouters @@ -174,7 +178,15 @@ class hostIf_DHCPv4Client { static void getLock(); static void releaseLock(); static GHashTable* getNotifyHash(); - + + #if defined(GTEST_ENABLE) + FRIEND_TEST(dhcpv4Test, isValidIPAddr); + FRIEND_TEST(dhcpv4Test, InvalidIPAddr); + FRIEND_TEST(dhcpv4Test, InvalidIP); + FRIEND_TEST(dhcpv4Test, InvalidIPAddr_alpha); + FRIEND_TEST(dhcpv4Test, getInterfaceName); + FRIEND_TEST(dhcpv4Test, isIfnameInroutetoDNSServer); + #endif }; #endif diff --git a/src/hostif/profiles/DHCPv4/gtest/Makefile.am b/src/hostif/profiles/DHCPv4/gtest/Makefile.am new file mode 100644 index 000000000..d0d878001 --- /dev/null +++ b/src/hostif/profiles/DHCPv4/gtest/Makefile.am @@ -0,0 +1,39 @@ +################################################################################ +# Copyright 2024 Comcast Cable Communications Management, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +AUTOMAKE_OPTIONS = subdir-objects +# Define the program name and the source files +bin_PROGRAMS = dhcpv4_gtest + +# Define the include directories +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -DYOCTO_BUILD -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/handlers/include -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/profiles/IP -I$(TOP_DIR)/src/hostif/profiles/DHCPv4 -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I/usr/include/rbus -I/usr/local/include/rbus $(GLIB_CFLAGS) $(G_THREAD_CFLAGS) -I/usr/include/libsoup-3.0 + +# Define the libraries to link against +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lsoup-3.0 + +# Define the compiler flags +COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) $(SOUP_LIBS) -fprofile-arcs -ftest-coverage + + +# Define the source files +dhcpv4_gtest_SOURCES = $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP.cpp $(TOP_DIR)/src/hostif/profiles/IP/Device_IP_Interface.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/DHCPv4/Device_DHCPv4_Client.cpp $(TOP_DIR)/src/hostif/profiles/DHCPv4/gtest/gtest_dhcpv4.cpp + +# Apply common properties to each program +dhcpv4_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) +dhcpv4_gtest_LDADD = $(COMMON_LDADD) +dhcpv4_gtest_CXXFLAGS = $(COMMON_CXXFLAGS) diff --git a/src/hostif/profiles/DHCPv4/gtest/gtest_dhcpv4.cpp b/src/hostif/profiles/DHCPv4/gtest/gtest_dhcpv4.cpp new file mode 100644 index 000000000..07677f5b8 --- /dev/null +++ b/src/hostif/profiles/DHCPv4/gtest/gtest_dhcpv4.cpp @@ -0,0 +1,197 @@ +/* + * Copyright 2024 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include "rdk_debug.h" + +#include "Device_DHCPv4_Client.h" + +#include +#include "cJSON.h" + +#include +#include + +#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/" +#define GTEST_DEFAULT_RESULT_FILENAME "hostif_gtest_report.json" +#define GTEST_REPORT_FILEPATH_SIZE 128 + +using namespace std; + +#define IFNAMSIZ 16 + +TEST(dhcpv4Test, isValidIPAddr) { + int instanceNumber = 1; + char* addr = (char*)"192.168.1.1"; + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + bool result = dhcpClient->isValidIPAddr(addr); + EXPECT_EQ(result, true); + } +} + +TEST(dhcpv4Test, InvalidIPAddr) { + int instanceNumber = 1; + char* addr = (char*)"192.168.1.1.1"; + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + bool result = dhcpClient->isValidIPAddr(addr); + EXPECT_EQ(result, false); + } +} + +TEST(dhcpv4Test, InvalidIP) { + int instanceNumber = 1; + char* addr = (char*)"192.168.256.1"; + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + bool result = dhcpClient->isValidIPAddr(addr); + EXPECT_EQ(result, false); + } +} + +TEST(dhcpv4Test, InvalidIPAddr_alpha) { + int instanceNumber = 1; + char* addr = (char*)"192.168.a.1"; + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + bool result = dhcpClient->isValidIPAddr(addr); + EXPECT_EQ(result, false); + } +} + +TEST(dhcpv4Test, getInterfaceName) { + int instanceNumber = 1; + char ifname[IFNAMSIZ]={'\0'}; + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + int result = dhcpClient->getInterfaceName(ifname); + EXPECT_EQ(result, OK); + } +} + + +/* TEST(dhcpv4Test, isIfnameInroutetoDNSServer) { + int instanceNumber = 1; + char* dnsServer = (char*)"8.8.8.8"; + char* ifname = (char*)"eth0"; + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + bool result = dhcpClient->isIfnameInroutetoDNSServer(dnsServer, ifname); + EXPECT_EQ(result, true); + } +} */ + +TEST(dhcpv4Test, get_Device_DHCPv4_ClientNumberOfEntries) { + int instanceNumber = 1; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + int result = dhcpClient->get_Device_DHCPv4_ClientNumberOfEntries(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(result, OK); + EXPECT_EQ(param.paramtype, hostIf_UnsignedIntType); + } +} + +TEST(dhcpv4Test, get_Device_DHCPv4_Client_IPRouters) { + int instanceNumber = 1; + bool bChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + bChanged = false; + int result = dhcpClient->get_Device_DHCPv4_Client_IPRouters(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(result, OK); + EXPECT_EQ(param.paramtype, hostIf_StringType); + } +} + +TEST(dhcpv4Test, get_Device_DHCPv4_Client_DnsServer) { + int instanceNumber = 1; + bool bChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + bChanged = false; + int result = dhcpClient->get_Device_DHCPv4_Client_DnsServer(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(result, OK); + EXPECT_EQ(param.paramtype, hostIf_StringType); + } +} + +TEST(dhcpv4Test, get_Device_DHCPv4_Client_InterfaceReference) { + int instanceNumber = 1; + bool bChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + bChanged = false; + int result = dhcpClient->get_Device_DHCPv4_Client_InterfaceReference(¶m, &bChanged); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(result, OK); + EXPECT_EQ(param.paramtype, hostIf_StringType); + } +} + +TEST(dhcpv4Test, Lock_ReleaseLock) { + int instanceNumber = 1; + hostIf_DHCPv4Client *dhcpClient= hostIf_DHCPv4Client::getInstance(instanceNumber); + if(dhcpClient) + { + dhcpClient->getLock(); + dhcpClient->releaseLock(); + EXPECT_EQ(0, 0); + } + dhcpClient->closeInstance(dhcpClient); + dhcpClient->closeAllInstances(); +} + +GTEST_API_ int main(int argc, char *argv[]){ + char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE]; + char buffer[GTEST_REPORT_FILEPATH_SIZE]; + + memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE ); + memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE ); + snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME); + + ::testing::GTEST_FLAG(output) = testresults_fullfilepath; + ::testing::InitGoogleMock(&argc, argv); + std::cout <<"running ut"<< std::endl; + return RUN_ALL_TESTS(); +} + diff --git a/src/hostif/profiles/Device/gtest/Makefile.am b/src/hostif/profiles/Device/gtest/Makefile.am new file mode 100644 index 000000000..44b882747 --- /dev/null +++ b/src/hostif/profiles/Device/gtest/Makefile.am @@ -0,0 +1,39 @@ +################################################################################ +# Copyright 2024 Comcast Cable Communications Management, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +AUTOMAKE_OPTIONS = subdir-objects +# Define the program name and the source files +bin_PROGRAMS = device_gtest + +# Define the include directories +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -DPARODUS -DUNIT_TEST -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/handlers/include -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/profiles/IP -I$(TOP_DIR)/src/hostif/profiles/Device -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I/usr/include/rbus -I/usr/local/include/rbus $(GLIB_CFLAGS) $(G_THREAD_CFLAGS) -I/usr/include/libsoup-3.0 + +# Define the libraries to link against +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lsoup-3.0 + +# Define the compiler flags +COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) $(SOUP_LIBS) -fprofile-arcs -ftest-coverage + + +# Define the source files +device_gtest_SOURCES = $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/Device/x_rdk_profile.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_NotificationHandler.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_notification.cpp $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/hostif/profiles/Device/gtest/gtest_device.cpp + +# Apply common properties to each program +device_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) +device_gtest_LDADD = $(COMMON_LDADD) +device_gtest_CXXFLAGS = $(COMMON_CXXFLAGS) diff --git a/src/hostif/profiles/Device/gtest/gtest_device.cpp b/src/hostif/profiles/Device/gtest/gtest_device.cpp new file mode 100644 index 000000000..f4995fef8 --- /dev/null +++ b/src/hostif/profiles/Device/gtest/gtest_device.cpp @@ -0,0 +1,234 @@ +/* + * Copyright 2024 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include + +#include "hostIf_utils.h" +#include "XrdkCentralComRFCStore.h" +#include "XrdkCentralComBSStore.h" +#include "rdk_debug.h" + +#include "x_rdk_profile.h" + +#include +#include "cJSON.h" + +#include +#include + +#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/" +#define GTEST_DEFAULT_RESULT_FILENAME "hostif_gtest_report.json" +#define GTEST_REPORT_FILEPATH_SIZE 128 + +using namespace std; + +TEST(DeviceTest, handleSetMsg) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.X_RDK_WebPA_DNSText.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + strncpy(param.paramValue, "fabric.xmidt.comcast.net", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->handleSetMsg(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(DeviceTest, handleGetMsg) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.X_RDK_WebPA_DNSText.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->handleGetMsg(¶m); + std::string value = getStringValue(¶m); + EXPECT_EQ(ret, OK); + EXPECT_EQ(value, "fabric.xmidt.comcast.net"); + } +} + +TEST(DeviceTest, get_WebPA_Server_URL) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.X_RDK_WebPA_Server.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->get_WebPA_Server_URL(¶m); + std::string value = getStringValue(¶m); + EXPECT_EQ(ret, OK); + EXPECT_EQ(value, ""); + } +} + +TEST(DeviceTest, get_WebPA_TokenServer_URL) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.X_RDK_WebPA_TokenServer.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->get_WebPA_TokenServer_URL(¶m); + std::string value = getStringValue(¶m); + EXPECT_EQ(ret, OK); + EXPECT_EQ(value, ""); + } +} + +TEST(DeviceTest, get_WebPA_DNSText_URL) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.X_RDK_WebPA_DNSText.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->get_WebPA_DNSText_URL(¶m); + std::string value = getStringValue(¶m); + EXPECT_EQ(ret, OK); + EXPECT_EQ(value, "fabric.xmidt.comcast.net"); + } +} + +TEST(DeviceTest, set_WebPA_DNSText_URL) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.X_RDK_WebPA_DNSText.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + strncpy(param.paramValue, "fabric.xmidt-eu.comcast.net", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->set_WebPA_DNSText_URL(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(DeviceTest, handleGetMsg_WebPA_Server_URL) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.X_RDK_WebPA_Server.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->handleGetMsg(¶m); + std::string value = getStringValue(¶m); + EXPECT_EQ(ret, OK); + EXPECT_EQ(value, ""); + } +} + +TEST(DeviceTest, handleSetMsg_InvalidParam) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.FriendlyName.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->handleSetMsg(¶m); + EXPECT_EQ(ret, NOK); + EXPECT_EQ(param.faultCode, fcInvalidParameterName); + } +} + +TEST(DeviceTest, handleGetMsg_InvalidParam) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.FriendlyName.URL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_WEBPA; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + X_rdk_profile* profile = X_rdk_profile::getInstance(); + if(profile) + { + int ret = profile->handleGetMsg(¶m); + EXPECT_EQ(ret, NOK); + EXPECT_EQ(param.faultCode, fcInvalidParameterName); + } + profile->closeInstance(); +} + +GTEST_API_ int main(int argc, char *argv[]){ + char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE]; + char buffer[GTEST_REPORT_FILEPATH_SIZE]; + + memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE ); + memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE ); + snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME); + + ::testing::GTEST_FLAG(output) = testresults_fullfilepath; + ::testing::InitGoogleMock(&argc, argv); + std::cout <<"running ut"<< std::endl; + return RUN_ALL_TESTS(); +} + diff --git a/src/hostif/profiles/Device/x_rdk_profile.h b/src/hostif/profiles/Device/x_rdk_profile.h index c3adb3cfc..56840635e 100644 --- a/src/hostif/profiles/Device/x_rdk_profile.h +++ b/src/hostif/profiles/Device/x_rdk_profile.h @@ -45,6 +45,9 @@ #include "hostIf_updateHandler.h" #include "XrdkCentralComBSStore.h" +#if defined(GTEST_ENABLE) +#include +#endif #define X_RDK_PREFIX_STR "Device.X_RDK_" #define X_RDK_WebPA_SERVER_URL_STPRING "Device.X_RDK_WebPA_Server.URL" @@ -78,6 +81,14 @@ class X_rdk_profile int set_WebConfig_URL(HOSTIF_MsgData_t *); int set_WebPA_DNSText_URL(HOSTIF_MsgData_t *); int set_WebConfig_SupplementaryServiceUrls_Telemetry(HOSTIF_MsgData_t *); + +#if defined(GTEST_ENABLE) + FRIEND_TEST(DeviceTest, set_WebPA_DNSText_URL); + FRIEND_TEST(DeviceTest, get_WebPA_Server_URL); + FRIEND_TEST(DeviceTest, get_WebPA_TokenServer_URL); + FRIEND_TEST(DeviceTest, get_WebPA_DNSText_URL); +#endif + public: static X_rdk_profile *getInstance(); static void closeInstance(); diff --git a/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp b/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp index fb1ef8c4e..39d2d3834 100644 --- a/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp +++ b/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp @@ -63,7 +63,11 @@ #include "mfrMgr.h" #include "Device_DeviceInfo.h" #include "hostIf_utils.h" +#ifdef RDKV_TR69 #include "pwrMgr.h" +#else +#include "power_controller.h" +#endif #include "rbus.h" #include @@ -74,6 +78,12 @@ #include "audioOutputPort.hpp" #include "sysMgr.h" +#ifdef RDKV_NM +#ifdef MEDIA_CLIENT +#include "netsrvmgrIarm.h" +#endif +#endif + #ifdef USE_REMOTE_DEBUGGER #include "rrdInterface.h" #endif @@ -93,6 +103,8 @@ #include "hostIf_NotificationHandler.h" #include "safec_lib.h" + + #define VERSION_FILE "/version.txt" #define SOC_ID_FILE "/var/log/socprov.log" #define PREFERRED_GATEWAY_FILE "/opt/prefered-gateway" @@ -116,20 +128,25 @@ #define MIN_PORT_RANGE 3000 #define MAX_PORT_RANGE 3020 +#define MEMINSIGHT_SERVICE "meminsight-runner.service" +#define MEMINSIGHT_ENABLE_FILE "/opt/.enable_meminsight" #define DEVICEID_SCRIPT_PATH "/lib/rdk/getDeviceId.sh" #define SCRIPT_OUTPUT_BUFFER_SIZE 512 #define ENTRY_WIDTH 64 +#define MigrationStatus "/opt/secure/persistent/MigrationStatus" GHashTable* hostIf_DeviceInfo::ifHash = NULL; GHashTable* hostIf_DeviceInfo::m_notifyHash = NULL; -GMutex hostIf_DeviceInfo::m_mutex; + +pthread_mutex_t hostIf_DeviceInfo::m_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutexattr_t hostIf_DeviceInfo::m_mutex_attr; +pthread_once_t hostIf_DeviceInfo::m_mutex_init_once = PTHREAD_ONCE_INIT; extern rbusHandle_t rbusHandle; void *ResetFunc(void *); static char stbMacCache[TR69HOSTIFMGR_MAX_PARAM_LEN] = {'\0'}; -static int mutex_lock = 0; static string reverseSSHArgs,shortsArgs,nonShortsArgs; map stunnelSSHArgs; const string sshCommand = "/lib/rdk/startTunnel.sh"; @@ -150,6 +167,9 @@ XRFCStorage hostIf_DeviceInfo::m_rfcStorage; #endif XBSStore* hostIf_DeviceInfo::m_bsStore; string hostIf_DeviceInfo::m_xrPollingAction = "0"; +#ifndef RDKV_TR69 +static bool bPowerControllerEnable; +#endif /****************************************************************************************************************************************************/ // Device.DeviceInfo Profile. Getters: @@ -262,23 +282,53 @@ void hostIf_DeviceInfo::closeAllInstances() } } -void hostIf_DeviceInfo::getLock() -{ - g_mutex_init(&hostIf_DeviceInfo::m_mutex); - g_mutex_lock(&hostIf_DeviceInfo::m_mutex); - mutex_lock = 1; +// Function to be called by pthread_once +void hostIf_DeviceInfo::initMutexAttributes() { + pthread_mutexattr_init(&hostIf_DeviceInfo::m_mutex_attr); + pthread_mutexattr_settype(&hostIf_DeviceInfo::m_mutex_attr, PTHREAD_MUTEX_ERRORCHECK); + pthread_mutex_init(&hostIf_DeviceInfo::m_mutex, &hostIf_DeviceInfo::m_mutex_attr); } -void hostIf_DeviceInfo::releaseLock() -{ - if(mutex_lock == 1) - { - mutex_lock = 0; - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); - g_mutex_unlock(&hostIf_DeviceInfo::m_mutex); +void hostIf_DeviceInfo::initMutexOnce() { + pthread_once(&m_mutex_init_once, (void (*)(void))&hostIf_DeviceInfo::initMutexAttributes); +} + +void hostIf_DeviceInfo::getLock() { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] Attempting to lock mutex\n", __FUNCTION__, __LINE__); + + // Ensure mutex is initialized + hostIf_DeviceInfo::initMutexOnce(); + + // Try to lock + int lock_result = pthread_mutex_lock(&hostIf_DeviceInfo::m_mutex); + if (lock_result == 0) { + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%d] Locked mutex\n", __FUNCTION__, __LINE__); + } else { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d] Failed to lock mutex: %s\n", + __FUNCTION__, __LINE__, strerror(lock_result)); } - else { - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%d] Mutex is not locked, cannot unlock... \n", __FUNCTION__, __LINE__); +} + +void hostIf_DeviceInfo::releaseLock() { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] Unlocking mutex...\n", __FUNCTION__, __LINE__); + + // Try to unlock and handle errors + int unlock_result = pthread_mutex_unlock(&hostIf_DeviceInfo::m_mutex); + + if (unlock_result == 0) { + // Successful unlock + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%d] Successfully unlocked mutex\n", + __FUNCTION__, __LINE__); + } else if (unlock_result == EPERM) { + // Thread doesn't own the mutex + RDK_LOG(RDK_LOG_WARN, LOG_TR69HOSTIF, + "[%s:%d] Thread doesn't own the mutex, skipping unlock\n", + __FUNCTION__, __LINE__); + } else { + // Other error + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s:%d] Error unlocking mutex: %s\n", + __FUNCTION__, __LINE__, strerror(unlock_result)); } } @@ -473,6 +523,50 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_SoftwareVersion(HOSTIF_MsgData_t * return OK; } +/** + * @brief This function retrieves the Migration Status from the MigrationStatus file. + * + * @param[out] stMsgData TR-069 Host interface message request. + * @param[in] pChanged Status of the operation. + * + * @return Returns the status of the operation. + * + * @retval OK if it is successful. + * @retval ERR_INTERNAL_ERROR if not able to fetch from device. + * @ingroup TR69_HOSTIF_DEVICEINFO_API + */ +int hostIf_DeviceInfo::get_Device_DeviceInfo_Migration_MigrationStatus(HOSTIF_MsgData_t * stMsgData, bool *pChanged) +{ + string line = "NOT_NEEDED"; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()] Entering..\n", __FUNCTION__ ); + ifstream file_read (MigrationStatus); + try { + if (file_read.is_open()) + { + if (file_read.peek() != EOF) { // Check if the file is not empty + std::getline(file_read, line); + } + file_read.close(); + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s()] Failed to open file\n", __FUNCTION__); + } + } + catch (const std::exception &e) { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s()]Exception caught.\n", __FUNCTION__); + return NOK; + } + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s()] value:%s\n", __FUNCTION__, line.c_str()); + int len = strlen(line.c_str()); + stMsgData->paramtype = hostIf_StringType; + strncpy(stMsgData->paramValue, line.c_str(), len); + stMsgData->paramValue[len+1] = '\0'; + stMsgData->paramLen = len; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()] Exiting..\n", __FUNCTION__ ); + return OK; +} + /** * @brief This function retrieves manufacturer specific data from the box using IARM Bus call. * The IARM Manager gets the manufacture information from mfr library. @@ -497,6 +591,10 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_Manufacturer(HOSTIF_MsgData_t * stM param.type = mfrSERIALIZED_TYPE_MANUFACTURER; iarm_ret = IARM_Bus_Call(IARM_BUS_MFRLIB_NAME, IARM_BUS_MFRLIB_API_GetSerializedData, ¶m, sizeof(param)); + std::string temp_buf(param.buffer); + std::replace(temp_buf.begin(), temp_buf.end(), ' ', '_'); + strncpy(param.buffer, temp_buf.c_str(), MAX_SERIALIZED_BUF - 1); + param.buffer[MAX_SERIALIZED_BUF - 1] = '\0'; RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s] IARM_BUS_MFRLIB_API_GetSerializedData returns params: %s with paramlen: %d.\r\n",__FUNCTION__, param.buffer, param.bufLen); if(iarm_ret == IARM_RESULT_SUCCESS) { @@ -1167,12 +1265,30 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_STB_MAC(HOSTIF_MsgDat string hostIf_DeviceInfo::getEstbIp() { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()]Entering..\n", __FUNCTION__); + #ifdef RDKV_TR69 + string retAddr; + #else string retAddr = ""; string ifc = ""; + #endif #if MEDIA_CLIENT + #ifdef RDKV_TR69 + IARM_Result_t ret = IARM_RESULT_SUCCESS; + IARM_BUS_NetSrvMgr_Iface_EventData_t param; + memset(¶m, 0, sizeof(param)); + try + { + ret = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME,IARM_BUS_NETSRVMGR_API_getSTBip, (void*)¶m, sizeof(param)); + if (ret != IARM_RESULT_SUCCESS ) + { + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF,"[%s():%d] IARM_BUS_NETSRVMGR_API_getActiveInterface failed \n", __FUNCTION__, __LINE__); + } + retAddr=param.activeIfaceIpaddr; + } + #else std::string postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetPrimaryInterface\"}"; - string response = getJsonRPCData(postData); + string response = getJsonRPCData(std::move(postData)); if(response.c_str()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); @@ -1213,9 +1329,9 @@ string hostIf_DeviceInfo::getEstbIp() { RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: getJsonRPCData failed\n", __FUNCTION__); } - + postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetIPSettings\", \"params\" : { \"interface\" : \"" + ifc + "\"}}"; - response = getJsonRPCData(postData); + response = getJsonRPCData(std::move(postData)); if(response.c_str()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); @@ -1256,7 +1372,8 @@ string hostIf_DeviceInfo::getEstbIp() { RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: getJsonRPCData failed\n", __FUNCTION__); } - //Legacy way of getting estb ip. + #endif +////Legacy way of getting estb ip. #else struct ifaddrs *ifAddrStr = NULL; @@ -1355,14 +1472,24 @@ string hostIf_DeviceInfo::getEstbIp() else { retAddr = tmp_buff; } - } catch (const std::exception& e) { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s] Exception getting IP\n",__FUNCTION__); + } + #ifndef RDKV_TR69 + catch (const std::exception& e) { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s] Exception getting IP\n",__FUNCTION__); + } + #endif +#endif +#ifdef RDKV_TR69 +catch (const std::exception &e) + { + RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s()]Exception caught %s\n", __FUNCTION__, e.what()); } #endif RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()]Exiting..\n", __FUNCTION__); return retAddr; } + bool hostIf_DeviceInfo::isRsshactive() { const string pidfile("/var/tmp/rssh.pid"); @@ -1404,6 +1531,8 @@ bool hostIf_DeviceInfo::isRsshactive() * @retval ERR_INTERNAL_ERROR if not able to fetch data from the device. * @ingroup TR69_HOSTIF_DEVICEINFO_API */ + + int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_STB_IP(HOSTIF_MsgData_t * stMsgData, bool *pChanged) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()]Entering..\n", __FUNCTION__); @@ -1432,6 +1561,15 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_STB_IP(HOSTIF_MsgData return OK; } + +#ifndef RDKV_TR69 +void hostIf_DeviceInfo::setPowerConInterface( bool isPwrContEnalbe) +{ + bPowerControllerEnable = isPwrContEnalbe; + +} +#endif + /** * @brief The X_COMCAST_COM_PowerStatus as get parameter results in the power status * being performed on the device. Power status of the device based on the front panel @@ -1445,6 +1583,8 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_STB_IP(HOSTIF_MsgData * @retval NOK if not able to fetch data from the device. * @ingroup TR69_HOSTIF_DEVICEINFO_API */ + +#ifdef RDKV_TR69 int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_PowerStatus(HOSTIF_MsgData_t * stMsgData, bool *pChanged) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()]Entering..\n", __FUNCTION__); @@ -1454,6 +1594,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_PowerStatus(HOSTIF_Ms int str_len = 0; IARM_Bus_PWRMgr_GetPowerState_Param_t param; memset(¶m, 0, sizeof(param)); + IARM_Result_t iarm_ret = IARM_RESULT_IPCCORE_FAIL; err = IARM_Bus_Call(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_API_GetPowerState, @@ -1472,7 +1613,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_PowerStatus(HOSTIF_Ms stMsgData->paramLen = str_len; stMsgData->paramtype = hostIf_StringType; ret = OK; - } catch (const std::exception &e) + } catch (const std::exception e) { RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception\r\n",__FUNCTION__); ret = NOK; @@ -1487,6 +1628,53 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_PowerStatus(HOSTIF_Ms //RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()]Exiting..\n", __FUNCTION__); return ret; } +#else +int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_PowerStatus(HOSTIF_MsgData_t * stMsgData, bool *pChanged) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()]Entering..\n", __FUNCTION__); + int ret = NOK, pwr_ret = -1; + const char *pwrState = "PowerOFF"; + int str_len = 0; + PowerController_PowerState_t curState = POWER_STATE_UNKNOWN, previousState = POWER_STATE_UNKNOWN; + + if(bPowerControllerEnable) { + pwr_ret = PowerController_GetPowerState(&curState, &previousState); + if (0 == pwr_ret) + { + pwrState = (curState==POWER_STATE_OFF)?"PowerOFF":(curState==POWER_STATE_ON)?"PowerON":"Standby"; + + //TODO: will comment this. + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Current state is : (%d)%s\n",curState, pwrState); + str_len = strlen(pwrState); + try + { + strncpy((char *)stMsgData->paramValue, pwrState, str_len); + stMsgData->paramValue[str_len+1] = '\0'; + stMsgData->paramLen = str_len; + stMsgData->paramtype = hostIf_StringType; + ret = OK; + } catch (const std::exception &e) + { + RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception\r\n",__FUNCTION__); + ret = NOK; + } + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed in power controller thunder cleint call for parameter : %s [param.type:%s with error code:%d]\n",stMsgData->paramName, pwrState, pwr_ret); + ret = NOK; + } + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Powercontroller Interface failed : %d. Try after sometime. \n", bPowerControllerEnable); + ret = NOK; + } + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s()]Exiting..\n", __FUNCTION__); + return ret; +} +#endif /** * @brief Get the filename of the firmware currently running on the device. @@ -1502,7 +1690,6 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_PowerStatus(HOSTIF_Ms */ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareFilename(HOSTIF_MsgData_t * stMsgData, bool *pChanged) { - errno_t rc = -1; string line; bool curFileFlag = true; ifstream curFwfile(CURENT_FW_FILE); @@ -1554,31 +1741,25 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareFilename(H } if(line.length()) { - char * cstr = new char [line.length()+1]; - rc=strcpy_s (cstr,(line.length()+1), line.c_str()); - if(rc!=EOK) + std::string::size_type pos = line.find(':'); + if (pos == std::string::npos) { - ERR_CHK(rc); - } - char * pch = NULL; - pch = strstr (cstr,":"); - pch++; - - while(isspace(*pch)) { - pch++; + return NOK; } - delete[] cstr; - - if(bCalledX_COMCAST_COM_FirmwareFilename && pChanged && strncmp(pch,backupX_COMCAST_COM_FirmwareFilename,_BUF_LEN_64 )) + std::string value = line.substr(pos + 1); + value.erase(0, value.find_first_not_of(" \t")); + + if(bCalledX_COMCAST_COM_FirmwareFilename && pChanged && strncmp(value.c_str(),backupX_COMCAST_COM_FirmwareFilename,_BUF_LEN_64 )) { *pChanged = true; } bCalledX_COMCAST_COM_FirmwareFilename = true; - strncpy(backupX_COMCAST_COM_FirmwareFilename,pch,sizeof(backupX_COMCAST_COM_FirmwareFilename) -1); //CID:136569 - Buffer size + strncpy(backupX_COMCAST_COM_FirmwareFilename,value.c_str(),sizeof(backupX_COMCAST_COM_FirmwareFilename) -1); //CID:136569 - Buffer size backupX_COMCAST_COM_FirmwareFilename[sizeof(backupX_COMCAST_COM_FirmwareFilename) -1] = '\0'; - strncpy(stMsgData->paramValue,pch,_BUF_LEN_64 ); - strncpy((char *) stMsgData->paramValue, pch, stMsgData->paramLen +1 ); + strncpy((char *) stMsgData->paramValue, value.c_str(), sizeof(stMsgData->paramValue)-1); + stMsgData->paramValue[sizeof(stMsgData->paramValue)-1] = '\0'; + stMsgData->paramLen = value.length(); } } @@ -1701,6 +1882,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadPerce { RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Last Field: [%s]\n", __FUNCTION__, lastField); strncpy(output, lastField, 8); + output[7] = '\0'; firmwareDownloadPercent = strtol (output, NULL, 10); RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] FirmwareDownloadPercent = [%d]\n", __FUNCTION__, firmwareDownloadPercent); put_int (stMsgData->paramValue, firmwareDownloadPercent); @@ -2622,7 +2804,7 @@ int hostIf_DeviceInfo::get_PartnerId_From_Script( string& current_PartnerId ) partnerId = ""; } } - current_PartnerId = partnerId; + current_PartnerId = std::move(partnerId); return OK; } @@ -2709,7 +2891,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportEna - snprintf((char *)stMsgData->paramValue, strlen(stMsgData->paramValue)-1, "%s", status); + snprintf((char *)stMsgData->paramValue, sizeof(stMsgData->paramValue), "%s", status); stMsgData->paramtype = hostIf_StringType; stMsgData->paramLen = strlen(stMsgData->paramValue); @@ -2743,7 +2925,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportIpa } } remoteInterface_file.close(); - snprintf((char *)stMsgData->paramValue, strlen(stMsgData->paramValue)-1, "%s",ipAddress); + snprintf((char *)stMsgData->paramValue, sizeof(stMsgData->paramValue), "%s",ipAddress); } else { @@ -2755,7 +2937,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportIpa { ERR_CHK(rc); } - snprintf((char *)stMsgData->paramValue, strlen(stMsgData->paramValue)-1, "%s",ipAddress); + snprintf((char *)stMsgData->paramValue, sizeof(stMsgData->paramValue), "%s",ipAddress); } stMsgData->paramtype = hostIf_StringType; @@ -2796,7 +2978,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportMAC } } remoteInterface_file.close(); - snprintf((char *)stMsgData->paramValue, strlen(stMsgData->paramValue)-1, "%s",macAddress); + snprintf((char *)stMsgData->paramValue, sizeof(stMsgData->paramValue), "%s",macAddress); } else { @@ -2808,7 +2990,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportMAC { ERR_CHK(rc); } - snprintf((char *)stMsgData->paramValue, strlen(stMsgData->paramValue)-1, "%s",macAddress); + snprintf((char *)stMsgData->paramValue, sizeof(stMsgData->paramValue), "%s",macAddress); } stMsgData->paramtype = hostIf_StringType; @@ -2825,7 +3007,7 @@ int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportMAC int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_XRPollingAction(HOSTIF_MsgData_t *stMsgData, bool *pChanged) { RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s] XRPollingAction = %s\n", __FUNCTION__, m_xrPollingAction.c_str()); - snprintf((char *)stMsgData->paramValue, strlen(stMsgData->paramValue)-1, "%s", m_xrPollingAction.c_str()); + snprintf((char *)stMsgData->paramValue, sizeof(stMsgData->paramValue), "%s", m_xrPollingAction.c_str()); stMsgData->paramtype = hostIf_StringType; stMsgData->paramLen = strlen(stMsgData->paramValue); @@ -2893,10 +3075,11 @@ int hostIf_DeviceInfo::findLocalPortAvailable() return -1; } + int hostIf_DeviceInfo::set_xOpsReverseSshTrigger(HOSTIF_MsgData_t *stMsgData) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s] Entering... \n",__FUNCTION__); -#ifdef PRIVACYMODES_CONTROL + #ifdef PRIVACYMODES_CONTROL string privacyModeValue; string queryJsonPrivacy = "{\"jsonrpc\":\"2.0\",\"id\":\"3\",\"method\": \"org.rdk.System.getPrivacyMode\" }"; string response = getJsonRPCData(queryJsonPrivacy); @@ -2984,6 +3167,86 @@ int hostIf_DeviceInfo::set_xOpsReverseSshTrigger(HOSTIF_MsgData_t *stMsgData) return OK; } +/** + * @brief This function retrieves the MigrationReady param value from the MigrationReadyFile. + * + * @param[out] stMsgData TR-069 Host interface message request. + * @param[in] pChanged Status of the operation. + * + * @return Returns the status of the operation. + * + * @retval OK if it is successful. + * @retval ERR_INTERNAL_ERROR if not able to fetch from device. + * @ingroup TR69_HOSTIF_DEVICEINFO_API + */ +int hostIf_DeviceInfo::get_Device_DeviceInfo_MigrationPreparer_MigrationReady(HOSTIF_MsgData_t * stMsgData, bool *pChanged) +{ + std::string response; + std::string postData; + std::string value; + int i = 0; + + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: call curl to get Components that are Ready..\n", __FUNCTION__); + + postData = "{\"jsonrpc\":\"2.0\",\"id\":\"3\",\"method\": \"org.rdk.MigrationPreparer.getComponentReadiness\" }"; + response = getJsonRPCData(postData); + + if(response.c_str()) + { + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); + cJSON* root = cJSON_Parse(response.c_str()); + if(root) + { + cJSON* jsonObj = cJSON_GetObjectItem(root, "result"); + if (jsonObj) + { + cJSON *ComponentList_obj = cJSON_GetObjectItem(jsonObj, "ComponentList"); + if (ComponentList_obj != NULL && cJSON_IsArray(ComponentList_obj)) + { + int ComponentList_obj_count = cJSON_GetArraySize(ComponentList_obj); + for ( ; i < ComponentList_obj_count-1; i++) + { + cJSON *Component = cJSON_GetArrayItem(ComponentList_obj, i); + if (cJSON_IsString(Component)) + { + printf(" - %s\n", Component->valuestring); + value = value + Component->valuestring + "_"; + } + } + cJSON *Component = cJSON_GetArrayItem(ComponentList_obj, i); + value = value + Component->valuestring ; + } + else + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] componentList is not present \n", __FUNCTION__); + return NOK; + } + } + else + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] json parse error, no \"result\" in the output from Thunder plugin\n", __FUNCTION__); + cJSON_Delete(root); + return NOK; + } + cJSON_Delete(root); + } + else + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: json parse error\n", __FUNCTION__); + } + } + else + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: curl init failed\n", __FUNCTION__); + } + + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(value.c_str()); + strncpy(stMsgData->paramValue, value.c_str(), stMsgData->paramLen); + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s()] Exiting..\n", __FUNCTION__ ); + return OK; +} + int hostIf_DeviceInfo::get_xOpsReverseSshArgs(HOSTIF_MsgData_t *stMsgData) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s] Entering... \n",__FUNCTION__); @@ -3362,6 +3625,7 @@ int hostIf_DeviceInfo::set_xRDKCentralComBootstrap(HOSTIF_MsgData_t * stMsgData) static bool ValidateInput_Arguments(char *input, FILE *tmp_fptr) { const char *apparmor_profiledir = "/etc/apparmor.d"; + const char *service_profiles_dir = "/etc/apparmor/service_profiles"; struct dirent *entry=NULL; DIR *dir=NULL; char *files_name = NULL; @@ -3435,11 +3699,28 @@ static bool ValidateInput_Arguments(char *input, FILE *tmp_fptr) sub_string=strstr(files_name, subtoken); if(sub_string != NULL) { fprintf(tmp_fptr,"%s\n",token); - } - else { - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Invalid arguments %s error found in the parser\n", subtoken); - free(files_name); - return FALSE; + } else { + bool profile_found = false; + DIR *service_profiles_dir_ptr = opendir(service_profiles_dir); + if (service_profiles_dir_ptr != NULL) { + struct dirent *profile_entry = NULL; + while ((profile_entry = readdir(service_profiles_dir_ptr)) != NULL) { + // Check if the file ends with .service.sp and matches subtoken + if (strstr(profile_entry->d_name, subtoken) != NULL && + strstr(profile_entry->d_name, ".service.sp") != NULL) { + profile_found = true; + break; + } + } + closedir(service_profiles_dir_ptr); + } + if (profile_found) { + fprintf(tmp_fptr, "%s\n", token); + } else { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "Invalid arguments %s error found in the parser\n", subtoken); + free(files_name); + return FALSE; + } } } token=strtok_r(NULL,"#",&sp); @@ -3693,6 +3974,18 @@ int hostIf_DeviceInfo::set_xRDKCentralComRFC(HOSTIF_MsgData_t * stMsgData) ret = set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerWebCfgData(stMsgData); } #endif + else if (strcasecmp(stMsgData->paramName,CANARY_START_TIME) == 0) + { + ret = set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpStart(stMsgData); + } + else if (strcasecmp(stMsgData->paramName,CANARY_END_TIME) == 0) + { + ret = set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpEnd(stMsgData); + } + else if (strcasecmp(stMsgData->paramName, X_MEMINSIGHT_ENABLE) == 0) + { + ret = set_Device_DeviceInfo_X_RDKCENTRAL_COM_XMemInsight_Enable(stMsgData); + } else if (strcasecmp(stMsgData->paramName,RDK_REBOOTSTOP_ENABLE) == 0) { ret = set_Device_DeviceInfo_X_RDKCENTRAL_COM_RebootStopEnable(stMsgData); @@ -3843,7 +4136,7 @@ int hostIf_DeviceInfo::get_xRDKCentralComRFCAccountId(HOSTIF_MsgData_t *stMsgDat RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: call curl to get Account ID..\n", __FUNCTION__); - string response = getJsonRPCData(postData); + string response = getJsonRPCData(std::move(postData)); if(response.c_str()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); @@ -3954,6 +4247,127 @@ int hostIf_DeviceInfo::set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerI return retVal; } +int hostIf_DeviceInfo::get_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggergetProfileData(HOSTIF_MsgData_t *stMsgData) +{ + stMsgData->paramtype = hostIf_StringType; + int retStatus = NOK; + const char *filename = "/etc/rrd/remote_debugger.json"; + FILE *fp = nullptr; + char *fileBuf = nullptr; + long fileSz = 0; + size_t bytesRead = 0; + cJSON *root = nullptr; + cJSON *filtered = nullptr; + char *outStr = nullptr; + size_t outLen = 0; + RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s] Entering …\n", __FUNCTION__); + fp = fopen(filename, "rb"); + if (!fp) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Cannot open %s\n", __FUNCTION__, filename); + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Leaving with NOK\n", __FUNCTION__); + return retStatus; + } + if (fseek(fp, 0L, SEEK_END) != 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] fseek failed\n", __FUNCTION__); + fclose(fp); + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Leaving with NOK\n", __FUNCTION__); + return retStatus; + } + fileSz = ftell(fp); + rewind(fp); + if (fileSz < 0) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] fileSz is negative, Returning....\n", __FUNCTION__); + fclose(fp); + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Leaving with NOK\n", __FUNCTION__); + return retStatus; + } + fileBuf = (char*)malloc((size_t)fileSz + 1); + if (!fileBuf) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] malloc(%ld) failed\n", __FUNCTION__, fileSz + 1); + fclose(fp); + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Leaving with NOK\n", __FUNCTION__); + return retStatus; + } + bytesRead = fread(fileBuf, 1U, (size_t)fileSz, fp); + fileBuf[bytesRead] = '\0'; + fclose(fp); fp = nullptr; + root = cJSON_Parse(fileBuf); + if (!root) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] JSON parse error: %s\n", __FUNCTION__, cJSON_GetErrorPtr()); + free(fileBuf); + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Leaving with NOK\n", __FUNCTION__); + return retStatus; + } + filtered = cJSON_CreateObject(); + if (!filtered) + { + free(fileBuf); + cJSON_Delete(root); + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Leaving with NOK\n", __FUNCTION__); + return retStatus; + } + + for (cJSON *top = root->child; top; top = top->next) + { + if (top->type != cJSON_Object) + { + continue; + } + cJSON *arr = cJSON_CreateArray(); + if (!arr) + { + free(fileBuf); + cJSON_Delete(root); + cJSON_Delete(filtered); + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Leaving with NOK\n", __FUNCTION__); + return retStatus; + } + for (cJSON *sub = top->child; sub; sub = sub->next) + { + cJSON_AddItemToArray(arr, cJSON_CreateString(sub->string)); + } + if (cJSON_GetArraySize(arr) > 0) + { + cJSON_AddItemToObject(filtered, top->string, arr); + } + else + { + cJSON_Delete(arr); + } + } + + outStr = cJSON_PrintUnformatted(filtered); + if (!outStr) + { + free(fileBuf); + cJSON_Delete(root); + cJSON_Delete(filtered); + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Leaving with NOK\n", __FUNCTION__); + return retStatus; + } + outLen = strlen(outStr); + if (outLen >= sizeof(stMsgData->paramValue)) + { + outLen = sizeof(stMsgData->paramValue) - 1; + } + memcpy(stMsgData->paramValue, outStr, outLen); + stMsgData->paramValue[outLen] = '\0'; + stMsgData->paramLen = outLen; + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Extracted profile map: %s\n", __FUNCTION__, outStr); + retStatus = OK; + free(fileBuf); + cJSON_Delete(root); + cJSON_Delete(filtered); + free(outStr); + RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s] Leaving with OK\n", __FUNCTION__); + return retStatus; +} + int hostIf_DeviceInfo::set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerWebCfgData (HOSTIF_MsgData_t *stMsgData) { char *issueStr = NULL; @@ -4003,7 +4417,7 @@ int hostIf_DeviceInfo::set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerW else { RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%d]: RBUS Publish event success for %s !!! \n ", __FUNCTION__, __LINE__, RRD_WEBCFG_ISSUE_EVENT); - retVal = NOK; + retVal = OK; } rbusValue_Release(value); rbusValue_Release(preValue); @@ -4016,6 +4430,135 @@ int hostIf_DeviceInfo::set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerW } #endif +int hostIf_DeviceInfo::set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpStart (HOSTIF_MsgData_t *stMsgData) +{ + int startTime = 0; + int retVal = NOK; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s] Entering... \n",__FUNCTION__); + startTime = atoi(stMsgData->paramValue); + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s] Start Time Value is %d \n",__FUNCTION__, startTime); + retVal = OK; + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s] Exiting... \n",__FUNCTION__); + return retVal; +} + +int hostIf_DeviceInfo::set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpEnd (HOSTIF_MsgData_t *stMsgData) +{ + int endTime = 0; + int retVal = NOK; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s] Entering... \n",__FUNCTION__); + endTime = atoi(stMsgData->paramValue); + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s] End Time Value is %d \n",__FUNCTION__, endTime); + retVal = OK; + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s] Exiting... \n",__FUNCTION__); + return retVal; +} + +int hostIf_DeviceInfo::set_Device_DeviceInfo_X_RDKCENTRAL_COM_XMemInsight_Enable(HOSTIF_MsgData_t *stMsgData) +{ + int ret = NOK; + bool is_xmem_enabled = false; + + if (!stMsgData) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d] NULL parameter passed\n", __FUNCTION__, __LINE__); + return NOK; + } + + if (stMsgData->paramtype != hostIf_BooleanType) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d] Invalid parameter type for %s. Expected boolean(0/1)\n", __FUNCTION__, __LINE__, stMsgData->paramName); + stMsgData->faultCode = fcInvalidParameterType; + return NOK; + } + + is_xmem_enabled = get_boolean(stMsgData->paramValue); + + if (is_xmem_enabled) + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] Enabling MemInsight feature\n", __FUNCTION__, __LINE__); + + std::ofstream enableFile(MEMINSIGHT_ENABLE_FILE); + if (enableFile.is_open()) + { + enableFile.close(); + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] Successfully enabled MemInsight. File created: %s\n", __FUNCTION__, __LINE__, MEMINSIGHT_ENABLE_FILE); + ret = OK; + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d] Failed to create MemInsight enable file: %s. Error: %s\n", __FUNCTION__, __LINE__, MEMINSIGHT_ENABLE_FILE, strerror(errno)); + stMsgData->faultCode = fcInternalError; + ret = NOK; + } + } + else + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] Disabling MemInsight feature\n", __FUNCTION__, __LINE__); + + std::ifstream checkFile(MEMINSIGHT_ENABLE_FILE); + if (checkFile.is_open()) + { + checkFile.close(); + if (remove(MEMINSIGHT_ENABLE_FILE) == 0) + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] Successfully disabled MemInsight. File removed: %s\n", __FUNCTION__, __LINE__, MEMINSIGHT_ENABLE_FILE); + ret = OK; + + int sysRet = v_secure_system("systemctl is-active %s", MEMINSIGHT_SERVICE); + + if (sysRet == 0) + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] %s is currently active\n", __FUNCTION__, __LINE__, MEMINSIGHT_SERVICE); + sysRet = v_secure_system("systemctl stop %s", MEMINSIGHT_SERVICE); + + if (sysRet == 0) + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] %s stopped successfully\n", __FUNCTION__, __LINE__, MEMINSIGHT_SERVICE); + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d] Failed to stop %s. Return code: %d\n", __FUNCTION__, __LINE__, MEMINSIGHT_SERVICE, sysRet); + } + sysRet = v_secure_system("systemctl is-active %s", MEMINSIGHT_SERVICE); + + if (sysRet != 0) + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] Confirmed: %s is now inactive\n", __FUNCTION__, __LINE__, MEMINSIGHT_SERVICE); + } + else + { + RDK_LOG(RDK_LOG_WARN, LOG_TR69HOSTIF, "[%s:%d] Warning: %s appears to still be active after stop command\n", __FUNCTION__, __LINE__, MEMINSIGHT_SERVICE); + } + } + else + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] MemInsight service %s is already inactive\n", __FUNCTION__, __LINE__, MEMINSIGHT_SERVICE); + } + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d] Failed to remove MemInsight enable file: %s. Error: %s\n", __FUNCTION__, __LINE__, MEMINSIGHT_ENABLE_FILE, strerror(errno)); + stMsgData->faultCode = fcInternalError; + ret = NOK; + } + } + else + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] MemInsight is already disabled. File not found: %s\n", __FUNCTION__, __LINE__, MEMINSIGHT_ENABLE_FILE); + ret = OK; + } + } + + if (ret == OK) + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d] Successfully set MemInsight enable to %s\n", __FUNCTION__, __LINE__, is_xmem_enabled ? "true" : "false"); + } + return ret; +} + int hostIf_DeviceInfo::set_Device_DeviceInfo_X_RDKCENTRAL_COM_RebootStopEnable(HOSTIF_MsgData_t *stMsgData) { int ret = NOK; @@ -4192,7 +4735,11 @@ int hostIf_DeviceInfo::set_xRDKCentralComDABRFCEnable(HOSTIF_MsgData_t *stMsgDat ofstream dabStatusFile(RDKV_DAB_ENABLE_FILE); dabStatusFile.close(); } else { - remove(RDKV_DAB_ENABLE_FILE); + if (remove(RDKV_DAB_ENABLE_FILE) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d] Failed to remove file %s.\n", __FUNCTION__, __LINE__, RDKV_DAB_ENABLE_FILE); + } else { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,"[%s:%d] File %s successfully removed.\n",__FUNCTION__, __LINE__, RDKV_DAB_ENABLE_FILE); + } } RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%d] Successfully set \"%s\" to \"%d\". \n", __FUNCTION__, __LINE__, stMsgData->paramName, enable); ret = OK; @@ -4252,6 +4799,7 @@ int hostIf_DeviceInfo::set_xRDKCentralComXREContainerRFCEnable(HOSTIF_MsgData_t return ret; } + void executeRfcMgr() { char buff[1024] = { '\0' }; @@ -4989,7 +5537,7 @@ int hostIf_DeviceInfo::get_X_RDKCENTRAL_COM_experience( HOSTIF_MsgData_t *stMsgD string experience = ""; std::string postData = "{\"jsonrpc\":\"2.0\",\"id\":\"3\",\"method\": \"org.rdk.AuthService.getExperience\" }"; - string resp = getJsonRPCData(postData); + string resp = getJsonRPCData(std::move(postData)); if(resp.c_str()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] curl response string = %s\n", __FUNCTION__, resp.c_str()); @@ -5041,6 +5589,7 @@ int hostIf_DeviceInfo::get_X_RDKCENTRAL_COM_experience( HOSTIF_MsgData_t *stMsgD return OK; } + /** * @brief This function identifying the imagename of the running image * This Value comes from "imagename" property in /version.txt file @@ -5101,7 +5650,6 @@ int hostIf_DeviceInfo::get_X_RDK_FirmwareName(HOSTIF_MsgData_t * stMsgData) int hostIf_DeviceInfo::set_xRDKDownloadManager_InstallPackage(HOSTIF_MsgData_t * stMsgData) { int ret = NOK; - const char *rdm_comm = "/etc/rdm/rdmBundleMgr.sh"; RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s] Entering..\n", __FUNCTION__ ); @@ -5110,9 +5658,9 @@ int hostIf_DeviceInfo::set_xRDKDownloadManager_InstallPackage(HOSTIF_MsgData_t * return NOK; } - RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Executing command - sh %s %s & \n", __FUNCTION__ , rdm_comm, stMsgData->paramValue); + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s] Executing Command rdm %s \n", __FUNCTION__ , stMsgData->paramValue); - ret = v_secure_system("backgroundrun sh %s %s", rdm_comm, stMsgData->paramValue); + ret = v_secure_system("backgroundrun rdm -v \"%s\" >> /opt/logs/rdm_status.log 2>&1", stMsgData->paramValue); if (ret != 0) { RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Failed to execute the command. Returned error code '%d'\n", __FUNCTION__, ret); @@ -5122,6 +5670,75 @@ int hostIf_DeviceInfo::set_xRDKDownloadManager_InstallPackage(HOSTIF_MsgData_t * RDK_LOG(RDK_LOG_TRACE1, LOG_TR69HOSTIF, "[%s] Exiting..\n", __FUNCTION__ ); return OK; } +#ifdef USE_REMOTE_DEBUGGER +int hostIf_DeviceInfo::set_xRDKDownloadManager_DownloadStatus(HOSTIF_MsgData_t * stMsgData) +{ + int ret = NOK; + bool isenabled = false; + LOG_ENTRY_EXIT; + + if(stMsgData->paramtype == hostIf_BooleanType) + { + isenabled = get_boolean(stMsgData->paramValue); + + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%d] Successfully set \"%s\" to \"%d\". \n", __FUNCTION__, __LINE__, stMsgData->paramName, isenabled); + + rbusError_t rc = RBUS_ERROR_BUS_ERROR; + rbusValue_t value, byVal, preValue; + rbusObject_t data; + rbusEvent_t event = {0}; + + rbusValue_Init(&value); + rbusValue_Init(&byVal); + rbusValue_Init(&preValue); + rbusValue_SetBoolean(value, isenabled); + rbusValue_SetBoolean(preValue, stMsgData->paramValue); + rbusValue_SetString(byVal, "tr69hostif"); + + + rbusObject_Init(&data, NULL); + rbusObject_SetValue(data, "value", value); + rbusObject_SetValue(data, "oldValue", preValue); + rbusObject_SetValue(data, "by", byVal); + + event.name = RDM_DOWNLOAD_EVENT; + event.data = data; + event.type = RBUS_EVENT_VALUE_CHANGED; + + rc = rbusEvent_Publish(rbusHandle, &event); + if ((rc != RBUS_ERROR_SUCCESS) && (rc != RBUS_ERROR_NOSUBSCRIBERS)) + { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%d]: RBUS Publish event failed for %s with return : %s !!! \n ", __FUNCTION__, __LINE__,RDM_DOWNLOAD_EVENT , rbusError_ToString(rc)); + ret = NOK; + } + else + { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "[%s:%d]: RBUS Publish event success for %s !!! \n ", __FUNCTION__, __LINE__, RDM_DOWNLOAD_EVENT); + ret = OK; + } + + rbusValue_Release(value); + rbusValue_Release(byVal); + rbusValue_Release(preValue); + rbusObject_Release(data); + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%d] Failed due to wrong data type for %s, please use boolean(0/1) to set.\n", __FUNCTION__, __LINE__, stMsgData->paramName); + stMsgData->faultCode = fcInvalidParameterType; + ret=NOK; + } + + return ret; +} +#endif + +#ifdef GTEST_ENABLE +bool (*ValidateInput_ArgumentsFunc()) (char *input, FILE *tmp_fptr) +{ + return &ValidateInput_Arguments; +} +#endif /* End of doxygen group */ /** * @} diff --git a/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.h b/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.h index a165e470f..f48d8827b 100644 --- a/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.h +++ b/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.h @@ -112,6 +112,10 @@ #include "hostIf_tr69ReqHandler.h" #include "hostIf_utils.h" +#if defined(GTEST_ENABLE) +#include +#endif + #ifndef NEW_HTTP_SERVER_DISABLE #include "XrdkCentralComRFCStore.h" #include "XrdkCentralComRFC.h" @@ -123,7 +127,7 @@ #define CDL_FLASH_FILE "/opt/cdl_flashed_file_name" #define CURENT_FW_FILE "/tmp/currently_running_image_name" -#define LOG_UPLOAD_SCR "backgroundrun /lib/rdk/UploadLogsNow.sh" +#define LOG_UPLOAD_SCR "backgroundrun /usr/bin/logupload uploadlogsnow >> /opt/logs/dcmscript.log 2>&1" #define CURRENT_LOG_UPLOAD_STATUS "/opt/loguploadstatus.txt" #define XRDK_BOOT_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_BootTime" @@ -134,6 +138,7 @@ /* Profile: X_RDKCENTRAL-COM_RDKDownloadManager. */ #define X_RDKDownloadManager_InstallPackage "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.InstallPackage" +#define X_RDKDownloadManager_DownloadStatus "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.DownloadStatus" /* Profile: X_RDKCENTRAL-COM_xOpsDeviceMgmt.Logging. */ #define xOpsDMUploadLogsNow_STR "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.Logging.xOpsDMUploadLogsNow" #define xOpsDMLogsUploadStatus_STR "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.Logging.xOpsDMLogsUploadStatus" @@ -191,6 +196,16 @@ #define RDK_REBOOTSTOP_ENABLE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Enable" #define APPARMOR_BLOCKLIST_PROCESS "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.NonRootSupport.ApparmorBlocklist" +/* Profile: X_RDKCENTRAL-COM_RFC.Canary */ +#define CANARY_START_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpStart" +#define CANARY_END_TIME "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpEnd" + +/* Profile: X_RDKCENTRAL-COM_RFC.Feature.xMemInsight */ +#define X_MEMINSIGHT_ENABLE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.xMemInsight.Enable" +#define X_MEMINSIGHT_ARGS "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.xMemInsight.Args" + +char* getLastField(char* line, char delimiter); + /** * @brief This class provides the interface for getting device information. * @ingroup TR69_HOSTIF_DEVICEINFO_CLASSES @@ -201,7 +216,11 @@ class hostIf_DeviceInfo { static GHashTable *m_notifyHash; - static GMutex m_mutex; + static pthread_mutex_t m_mutex; + static pthread_mutexattr_t m_mutex_attr; + static pthread_once_t m_mutex_init_once; + static void initMutexOnce(); + static void initMutexAttributes(); int dev_id; @@ -252,7 +271,7 @@ class hostIf_DeviceInfo { std::string m_strXOpsDevManageableNotification; std::string m_strXOpsRPCFwDwldStartedNotification; bool m_bXOpsRPCFwDwldCompletedNotification; - + string getEstbIp(); bool isRsshactive(); bool isShortsEnabled(); @@ -293,6 +312,47 @@ class hostIf_DeviceInfo { int set_xOpsRPCFwDwldCompletedNotification(HOSTIF_MsgData_t*); int set_xOpsRPCRebootPendingNotification(HOSTIF_MsgData_t*); static void systemMgmtTimePathMonitorThr(); + +#if defined(GTEST_ENABLE) + FRIEND_TEST(deviceTest, getEstbIp); + FRIEND_TEST(deviceTest, NewNtpEnable); + FRIEND_TEST(deviceTest, set_xRDKCentralComRFCLoudnessEquivalenceEnable); + FRIEND_TEST(deviceTest, set_xRDKCentralComXREContainerRFCEnable); + FRIEND_TEST(deviceTest, set_xRDKCentralComXREContainerRFCDisable); + FRIEND_TEST(deviceTest, set_xRDKCentralComXREContainerRFCInvalidtype); + FRIEND_TEST(deviceTest, set_xOpsRPCRebootPendingNotification); + FRIEND_TEST(deviceTest, set_xRDKCentralComApparmorBlocklist); + FRIEND_TEST(deviceTest, set_xOpsRPCFwDwldCompletedNotification); + FRIEND_TEST(deviceTest, set_xOpsRPCFwDwldStartedNotification); + FRIEND_TEST(deviceTest, set_xOpsRPCDevManageableNotification); + FRIEND_TEST(deviceTest, set_xRDKCentralComXREContainerRFCEnable); + FRIEND_TEST(deviceTest, get_xOpsRPCFwDwldCompletedNotification); + FRIEND_TEST(deviceInfoTest, findLocalPortAvailable); + FRIEND_TEST(deviceTest, set_xRDKCentralComRFCRetrieveNow); + FRIEND_TEST(deviceTest, set_xRDKCentralComXREContainerRFCEnable); + FRIEND_TEST(deviceTest, set_xOpsRPCDevManageableNotification); + FRIEND_TEST(deviceTest, get_xOpsRPCFwDwldCompletedNotification); + FRIEND_TEST(deviceTest, set_xOpsRPCRebootPendingNotification); + FRIEND_TEST(deviceTest, set_xRDKCentralComNewNtpEnable); + FRIEND_TEST(deviceTest, NewNtpEnable_Disable); + FRIEND_TEST(deviceTest, findLocalPortAvailable); + FRIEND_TEST(deviceTest, get_xOpsRPCRebootPendingNotification); + FRIEND_TEST(deviceTest, get_xOpsRPCFwDwldStartedNotification); + FRIEND_TEST(deviceTest, ScheduleAutoReboot); + FRIEND_TEST(deviceTest, set_xRDKCentralComRFCAutoRebootEnable); + FRIEND_TEST(deviceTest, set_xRDKCentralComRFCLoudnessEquivalenceEnable); + FRIEND_TEST(deviceTest, set_xOpsDeviceMgmtRPCRebootNow); + FRIEND_TEST(deviceTest, set_xRDKCentralComDABRFCEnable); + FRIEND_TEST(deviceTest, set_xRDKCentralComDABRFCDisable); + FRIEND_TEST(deviceTest, set_xRDKCentralComDABRFCInvalidtype); + FRIEND_TEST(deviceTest, get_xOpsRPCDevManageableNotification); + FRIEND_TEST(deviceTest, set_xRDKCentralComRFCRoamTrigger); + FRIEND_TEST(deviceTest, set_xRDKCentralComRFCLoudnessEquivalenceEnable_InvalidType); + FRIEND_TEST(deviceTest, set_xRDKCentralComRFCAutoRebootEnable_Invalidtype); + FRIEND_TEST(deviceTest, set_xRDKCentralComXREContainerRFCEnable_FileRemoved); + FRIEND_TEST(deviceTest, NewNtpEnable_Disable_FileRemoved); + FRIEND_TEST(deviceTest, get_xRDKCentralComRFCAccountId); +#endif public: @@ -313,6 +373,9 @@ class hostIf_DeviceInfo { static int sendDeviceMgtNotification(const char* source, const char* type); GHashTable* getNotifyHash(); + #ifndef RDKV_TR69 + static void setPowerConInterface( bool isPwrContEnalbe); + #endif // void runSystemMgmtTimePathMonitor(); /** @@ -512,6 +575,43 @@ class hostIf_DeviceInfo { * @see get_Device_DeviceInfo_ProductClass. */ int get_Device_DeviceInfo_SoftwareVersion(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + /** + * @brief get_Device_DeviceInfo_MigrationPreparer_MigrationReady. + * + * This function provides the component list which are ready for migration. + * The component name (human readable string). + * + * @return The status of the operation. + * + * @retval OK if DeviceInfo_MigrationPreparer_MigrationReady was successfully fetched. + :1 + * @retval ERR_INTERNAL_ERROR if not able to fetch from device. + * + * @sideeffect All necessary structures and buffers are deallocated. + * @execution Synchronous. + * + * @see get_Device_DeviceInfo_MigrationPreparer_MigrationReady. + */ + int get_Device_DeviceInfo_MigrationPreparer_MigrationReady(HOSTIF_MsgData_t *, bool *pChanged = NULL); + + /** + * @brief get_Device_DeviceInfo_Migration_MigrationStatus. + * + * This function provides the status of the migration. + * The Status (human readable string). + * + * @return The status of the operation. + * + * @retval OK if Device_DeviceInfo_Migration_MigrationStatus was successfully fetched. + * @retval ERR_INTERNAL_ERROR if not able to fetch from device. + * + * @sideeffect All necessary structures and buffers are deallocated. + * @execution Synchronous. + * + * @see get_Device_DeviceInfo_Migration_MigrationStatus. + */ + int get_Device_DeviceInfo_Migration_MigrationStatus(HOSTIF_MsgData_t *, bool *pChanged = NULL); /** * @brief get_Device_DeviceInfo_IUI_Version. @@ -1183,7 +1283,42 @@ class hostIf_DeviceInfo { int set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerIssueType(HOSTIF_MsgData_t *); int set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerWebCfgData(HOSTIF_MsgData_t *); + int get_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggergetProfileData(HOSTIF_MsgData_t *); #endif + + /* + * @brief set_Device_DeviceInfo_X_RDKCENTRAL_COM_CanaryStartTime, set_Device_DeviceInfo_X_RDKCENTRAL_COM_CanaryEndTime, set_Device_DeviceInfo_X_RDKCENTRAL_COM_CanaryExtendTime + * + * This method is to get the Issuetype from QA. + * with following TR-069 definition: + * Parameter Name: Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpStart, + * Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpEnd, + * Data type: String - Arguments Start/End Time + * + * @retval OK if it is successful. + * @retval NOK if operation fails. + */ + + int set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpStart(HOSTIF_MsgData_t *); + int set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpEnd(HOSTIF_MsgData_t *); + + + /* + * @brief set_Device_DeviceInfo_X_RDKCENTRAL_COM_XMemInsight_Enable + * + * This method is used to enable/disable the xmeminsight memory & CPU Analysis Tool. + * with following TR-069 definition: + * Parameter Name: Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.xMemInsight.Enable + * Data type: boolean - Enable (True)/ disable (False) xmeminsight tool. + * + * @retval OK if it is successful. + * @retval NOK if operation fails. + */ + + int set_Device_DeviceInfo_X_RDKCENTRAL_COM_XMemInsight_Enable(HOSTIF_MsgData_t *); + + + /* * @brief set_Device_DeviceInfo_X_RDKCENTRAL_COM_RebootStopEnable * @@ -1442,6 +1577,7 @@ class hostIf_DeviceInfo { int get_X_RDK_FirmwareName(HOSTIF_MsgData_t *); int set_xRDKDownloadManager_InstallPackage(HOSTIF_MsgData_t *); + int set_xRDKDownloadManager_DownloadStatus(HOSTIF_MsgData_t *); }; /* End of doxygen group */ /** diff --git a/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.h b/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.h index 66a69a575..3b8206c1c 100755 --- a/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.h +++ b/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.h @@ -59,6 +59,10 @@ #include "hostIf_utils.h" #include "hostIf_updateHandler.h" +#if defined(GTEST_ENABLE) +#include +#endif + #define PARAM_LEN 256 /** @@ -83,6 +87,10 @@ class hostIf_DeviceProcessStatusInterface unsigned int getNumOfProcessEntries(); int getProcessStatusCPUUsage(); +#if defined(GTEST_ENABLE) + FRIEND_TEST(processTest, getProcessStatusCPUUsage); +#endif + public: static hostIf_DeviceProcessStatusInterface *getInstance(int dev_id); diff --git a/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp b/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp index d5923a09b..ef7fccbb8 100755 --- a/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp +++ b/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp @@ -38,6 +38,7 @@ #include "Device_DeviceInfo_Processor.h" + GHashTable* hostIf_DeviceProcessorInterface::ifHash = NULL; GMutex hostIf_DeviceProcessorInterface::m_mutex; @@ -181,7 +182,8 @@ int hostIf_DeviceProcessorInterface::get_Device_DeviceInfo_Processor_Architectur uname(&utsName); RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Get Architecture value: '%s'\n", utsName.machine); - strncpy(stMsgData->paramValue, utsName.machine, strlen(utsName.machine)); + strncpy(stMsgData->paramValue, utsName.machine, sizeof(stMsgData->paramValue) - 1); + stMsgData->paramValue[sizeof(stMsgData->paramValue) - 1] = '\0'; if(pChanged && bCalledArchitecture && strncpy(stMsgData->paramValue,backupArchitecture,strlen(stMsgData->paramValue))) { *pChanged = true; diff --git a/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp b/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp index 96c031c8b..7c74d407f 100755 --- a/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp +++ b/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp @@ -44,6 +44,7 @@ #define BSP_COMPLETE_TMP "/tmp/bspcomplete" #define RFC_DIRECTORY "/opt/RFC" #define AUTH_SERVICE_PARODUS_RESTART "/tmp/authservice_parodus_restart" +#define MAX_FILENAME_LENGTH 256 #define CURL_EASY_SETOPT(CURL , CURLoption , Value)\ if (curl_easy_setopt(CURL , CURLoption , Value) != CURLE_OK ) {\ @@ -109,7 +110,9 @@ bool createBspCompleteFiles() RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,"Directory %s already exists.\n", RFC_DIRECTORY); } + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,"Creating BSP Complete File %s\n", BSP_COMPLETE); createFile(BSP_COMPLETE); + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,"Creating BSP Complete File %s in tmp Directory\n", BSP_COMPLETE_TMP); createFile(BSP_COMPLETE_TMP); return true; } @@ -151,6 +154,7 @@ void XBSStore::getAuthServicePartnerID() if (foundWWW && foundAuthService && fileExists(filePath)) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s File %s already exists. Monitoring for modifications...\n", __FUNCTION__, targetFile.c_str()); wd = inotify_add_watch(inotifyFd, filePath.c_str(), IN_CLOSE_WRITE); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Watch descriptor (wd) value: %d\n", wd); partnerIdWatchAdded = true; // Check if the BSP_COMPLETE file exists @@ -167,10 +171,12 @@ void XBSStore::getAuthServicePartnerID() if (foundAuthService) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Directory %s already exists.\n", authServiceDir.c_str()); wd = inotify_add_watch(inotifyFd, authServiceDir.c_str(), IN_CREATE | IN_CLOSE_WRITE); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Watch descriptor (wd) value: %d\n", wd); RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Now monitoring %s for partnerId3.dat creation and modifications...\n", authServiceDir.c_str()); } else { // Add a watch on /opt/www to monitor for authService creation wd = inotify_add_watch(inotifyFd, wwwDir.c_str(), IN_CREATE); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Watch descriptor (wd) value: %d\n", wd); RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Now monitoring %s for authService directory creation...\n", wwwDir.c_str()); } } @@ -187,42 +193,62 @@ void XBSStore::getAuthServicePartnerID() struct inotify_event *event = (struct inotify_event *)ptr; // If www is created - if (!foundWWW && (event->mask & IN_CREATE) && (event->mask & IN_ISDIR) && strcmp(event->name, "www") == 0) { - foundWWW = true; - RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Directory %s created!\n", wwwDir.c_str()); - - // Immediately check if authService already exists - foundAuthService = fileExists(authServiceDir); - if (foundAuthService) { - RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Directory %s already exists.\n", authServiceDir.c_str()); - wd = inotify_add_watch(inotifyFd, authServiceDir.c_str(), IN_CREATE | IN_CLOSE_WRITE); - RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Now monitoring %s for partnerId3.dat creation and modifications...\n", authServiceDir.c_str()); - } else { + if (!foundWWW && (event->mask & IN_CREATE) && (event->mask & IN_ISDIR) ) { + char nameBuf[NAME_MAX +1] = {0}; + strncpy(nameBuf, event->name, NAME_MAX); + if (strcmp(nameBuf, "www") == 0) + { + foundWWW = true; + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Directory %s created!\n", wwwDir.c_str()); + + // Immediately check if authService already exists + foundAuthService = fileExists(authServiceDir); + if (foundAuthService) { + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Directory %s already exists.\n", authServiceDir.c_str()); + wd = inotify_add_watch(inotifyFd, authServiceDir.c_str(), IN_CREATE | IN_CLOSE_WRITE); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Watch descriptor (wd) value: %d\n", wd); // Log the value of wd + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Now monitoring %s for partnerId3.dat creation and modifications...\n", authServiceDir.c_str()); + } else { // Add a new watch for /opt/www/authService creation - wd = inotify_add_watch(inotifyFd, wwwDir.c_str(), IN_CREATE); - RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Now monitoring %s for authService directory creation...\n", wwwDir.c_str()); + wd = inotify_add_watch(inotifyFd, wwwDir.c_str(), IN_CREATE); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Watch descriptor (wd) value: %d\n", wd); // Log the value of wd + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Now monitoring %s for authService directory creation...\n", wwwDir.c_str()); + } } - } + } // If authService is created - else if (foundWWW && !foundAuthService && (event->mask & IN_CREATE) && (event->mask & IN_ISDIR) && strcmp(event->name, "authService") == 0) { - foundAuthService = true; + else if (foundWWW && !foundAuthService && (event->mask & IN_CREATE) && (event->mask & IN_ISDIR)) { + char nameBuf[NAME_MAX +1]; + strncpy(nameBuf, event->name, NAME_MAX); + nameBuf[NAME_MAX] ='\0'; + if (strcmp(nameBuf, "authService") == 0) { + foundAuthService = true; RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "Directory %s created!\n", authServiceDir.c_str()); - // Add a new watch for partnerId3.dat + // Add a new watch for partnerId3.dat wd = inotify_add_watch(inotifyFd, authServiceDir.c_str(), IN_CREATE | IN_CLOSE_WRITE); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Watch descriptor (wd) value: %d\n", wd); // Log the value of wd RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Now monitoring %s for partnerId3.dat creation and modifications...\n", authServiceDir.c_str()); + } } // If partnerId3.dat is created - else if (foundAuthService && !partnerIdWatchAdded && (event->mask & IN_CREATE) && strcmp(event->name, targetFile.c_str()) == 0) { - RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s File %s created!\n", __FUNCTION__, event->name); - partnerIdWatchAdded = true; - partnerFileUpdated = true; - - // Monitor the file for close after writing - RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Now monitoring %s for modifications...\n", filePath.c_str()); - break; + else if (foundAuthService && !partnerIdWatchAdded && (event->mask & IN_CREATE)) { + // Create a null-terminated copy of event->name + char safeEventName[NAME_MAX + 1]; + strncpy(safeEventName, event->name, NAME_MAX); + safeEventName[NAME_MAX] = '\0'; // Ensure null termination + + if (strcmp(safeEventName, targetFile.c_str()) == 0) { + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s File %s created!\n", __FUNCTION__, safeEventName); + partnerIdWatchAdded = true; + partnerFileUpdated = true; + + // Monitor the file for close after writing + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Now monitoring %s for modifications...\n", filePath.c_str()); + break; + } } // If partnerId3.dat is modified @@ -255,12 +281,15 @@ void XBSStore::getAuthServicePartnerID() // Create a new file "/tmp/authservice_parodus_restart" createFile(AUTH_SERVICE_PARODUS_RESTART); RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,"BSP_COMPLETE exists. Created /tmp/authservice_parodus_restart.\n"); - } else { - // If BSP_COMPLETE doesn't exist, create it so parodus.service can start. - createBspCompleteFiles(); - RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,"BSP_COMPLETE did not exist. Created BSP_COMPLETE.\n"); - } + } } + + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,"Check and create BSP_COMPLETE for parodus.service to start.\n"); + if (!fileExists(BSP_COMPLETE)) { + // If BSP_COMPLETE doesn't exist, create it so parodus.service can start. + createBspCompleteFiles(); + RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,"BSP_COMPLETE did not exist. Created BSP_COMPLETE.\n"); + } } else { @@ -492,11 +521,11 @@ string XBSStore::getRawValue(const string &key) mtx.lock(); unordered_map::const_iterator it = m_dict.find(key); if (it == m_dict.end()) { - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); mtx.unlock(); return ""; } - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); mtx.unlock(); RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF, "Leaving %s : Value = %s \n", __FUNCTION__, it->second.c_str()); @@ -669,7 +698,7 @@ faultCode_t XBSStore::overrideValue(HOSTIF_MsgData_t *stMsgData) RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "Unable to Set Value for given Param\n"); stMsgData->faultCode = fcInternalError; } - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); mtx.unlock(); RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF, "Leaving %s \n", __FUNCTION__); return stMsgData->faultCode; @@ -761,7 +790,7 @@ bool XBSStore::init() mtx.lock(); if(m_initDone) { - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); mtx.unlock(); return m_initDone; } @@ -770,7 +799,7 @@ bool XBSStore::init() m_initDone = loadBSPropertiesIntoCache(); RDK_LOG (RDK_LOG_TRACE1, LOG_TR69HOSTIF, "Leaving %s \n", __FUNCTION__); - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%d] Unlocking mutex... \n", __FUNCTION__, __LINE__); mtx.unlock(); return m_initDone; } diff --git a/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.h b/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.h index 015712d70..918cafa21 100755 --- a/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.h +++ b/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.h @@ -28,8 +28,18 @@ #include #include "cJSON.h" +#if defined(GTEST_ENABLE) +#include +#endif + using namespace std; +#if defined(GTEST_ENABLE) +void createFile(const char* path); +bool createBspCompleteFiles(); +bool createDirectory(const char* path); +#endif + class XBSStore { public: @@ -69,6 +79,19 @@ class XBSStore bool loadFromJson(); bool clearRfcValues(); static void getAuthServicePartnerID(); + +#if defined(GTEST_ENABLE) + FRIEND_TEST(bsStoreTest, getRawValue); + FRIEND_TEST(bsStoreTest, setRawValue); + FRIEND_TEST(bsStoreTest, initBSPropertiesFileName); + FRIEND_TEST(StoreClearTest, resetCacheAndStore); + FRIEND_TEST(StoreClearTest, clearRfcValues); + FRIEND_TEST(bsStoreTest, getPartnerDeviceConfig); + FRIEND_TEST(bsStoreTest, getPartnerDeviceConfig_generic); + FRIEND_TEST(bsStoreTest, getPartnerDeviceConfig_FileRemoved); + FRIEND_TEST(bsStoreTest, getRawValue_Empty); + FRIEND_TEST(StoreClearTest, setRawValue_Flush); +#endif }; #endif // XRDKCENTRALCOMBSSTORE_H diff --git a/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.h b/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.h index 8004a6e92..8e6b4d51a 100755 --- a/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.h +++ b/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.h @@ -28,6 +28,10 @@ #include #include "hostIf_msgHandler.h" +#if defined(GTEST_ENABLE) +#include +#endif + using namespace std; typedef struct _BS_JournalData_t @@ -73,6 +77,14 @@ class XBSStoreJournal bool loadJournalRecordsIntoCache(); string getBuildTime(); string getTime(); + +#if defined(GTEST_ENABLE) + FRIEND_TEST(bsStoreJournalTest, getBuildTime); + FRIEND_TEST(bsStoreJournalTest, resetClearRfc); + FRIEND_TEST(bsStoreJournalTest, clearRfcAndGetDefaultValue); + FRIEND_TEST(bsStoreJournalTest, constructor); + FRIEND_TEST(bsStoreJournalTest, getBuildTime_Version); +#endif }; #endif //XRDKCENTRALCOMBSSTOREJOURNAL_H diff --git a/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp b/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp index 7268e9140..a63a0114e 100644 --- a/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp +++ b/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp @@ -99,7 +99,12 @@ bool XRFCStorage::init() // get the file path IniFile file; - file.load(RFC_PROPERTIES_FILE); + if(!file.load(RFC_PROPERTIES_FILE)) + { + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF, "[%s] [%d] Failed to load file: %s\n", __FUNCTION__, __LINE__, RFC_PROPERTIES_FILE); + return false; + } + m_storageFile = file.value(TR181_RFC_STORE_KEY); if (m_storageFile.empty()) { diff --git a/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.h b/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.h index e7e91fd8f..fe3707451 100644 --- a/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.h +++ b/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.h @@ -23,6 +23,10 @@ #include "IniFile.h" #include +#if defined(GTEST_ENABLE) +#include +#endif + using namespace std; class XRFCStorage @@ -41,6 +45,11 @@ class XRFCStorage IniFile m_storage; string m_storageFile; bool m_storageLoaded; + +#if defined(GTEST_ENABLE) + FRIEND_TEST(rfcStorageTest, init); + FRIEND_TEST(StoreClearTest, init); +#endif }; #endif // XRDKCENTRALCOMRFC_H diff --git a/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp b/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp index 2dd8384a0..21441f830 100644 --- a/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp +++ b/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp @@ -245,7 +245,7 @@ faultCode_t XRFCStore::getValue(HOSTIF_MsgData_t *stMsgData) return fcInternalError; } string rawValue = getRawValue(stMsgData->paramName); - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "rawValue: %s\n", rawValue.c_str()); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "Parameter: %s, rawValue: %s\n", stMsgData->paramName, rawValue.c_str()); if(rawValue.length() > 0) { putValue(stMsgData, rawValue.c_str()); @@ -265,7 +265,7 @@ faultCode_t XRFCStore::getValue(HOSTIF_MsgData_t *stMsgData) putValue(stMsgData, rawValue.c_str()); stMsgData->faultCode = fcNoFault; - RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "stMsgData->paramValue = %s\n", stMsgData->paramValue); + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "stMsgData->paramValue = %s\n", stMsgData->paramValue); } else { diff --git a/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.h b/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.h index 2f561671b..dda061a4f 100644 --- a/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.h +++ b/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.h @@ -25,8 +25,16 @@ #include #include +#if defined(GTEST_ENABLE) +#include +#endif + using namespace std; +#if defined(GTEST_ENABLE) +bool init_rfcdefaults(); +#endif + class XRFCStore { public: @@ -61,6 +69,16 @@ class XRFCStore void initTR181PropertiesFileName(); bool loadFileToCache(const string &filename, unordered_map &dict); bool loadTR181PropertiesIntoCache(); + +#if defined(GTEST_ENABLE) + FRIEND_TEST(rfcStoreTest, getRawValue); + FRIEND_TEST(rfcStoreTest, getRawValue_NONPERSISTENT_FILE); + FRIEND_TEST(rfcStoreTest, setRawValue_NONPERSISTENT_FILE); + FRIEND_TEST(rfcStoreTest, writeHashToFile); + FRIEND_TEST(rfcStoreTest, loadTR181PropertiesIntoCache); + FRIEND_TEST(rfcStoreTest, setRawValue_Invalid_FILE); + FRIEND_TEST(rfcStoreTest, loadFileToCache); +#endif }; #endif // XRDKCENTRALCOMRFCSTORE_H diff --git a/src/hostif/profiles/DeviceInfo/gtest/Makefile.am b/src/hostif/profiles/DeviceInfo/gtest/Makefile.am index 4612c850b..255f9b672 100755 --- a/src/hostif/profiles/DeviceInfo/gtest/Makefile.am +++ b/src/hostif/profiles/DeviceInfo/gtest/Makefile.am @@ -21,26 +21,17 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = devieInfo_gtest # Define the include directories -COMMON_CPPFLAGS = -std=c++11 -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I$(TOP_DIR)/src/hostif/handlers/include -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/hostif/httpserver/include -I$(TOP_DIR)/src/hostif/handlers/src -I/usr/include/rbus -I/usr/local/include/rbus - -if LIBSOUP3_ENABLE -COMMON_CPPFLAGS += -I/usr/include/libsoup-3.0 -DLIBSOUP3_ENABLE -else -COMMON_CPPFLAGS += -I/usr/include/libsoup-2.4 -endif +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -DUSE_DEV_PROPERTIES_CONF -DPARODUS -DUNIT_TEST -DUSE_REMOTE_DEBUGGER -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I$(TOP_DIR)/src/hostif/handlers/include -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/hostif/httpserver/include -I$(TOP_DIR)/src/hostif/handlers/src -I/usr/include/rbus -I/usr/local/include/rbus -I/usr/remote_debugger/src/ -I/usr/include/libsoup-3.0 # Define the libraries to link against -COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl - -if LIBSOUP3_ENABLE -COMMON_LDADD += -lsoup-3.0 -endif +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lsoup-3.0 # Define the compiler flags COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) $(SOUP_LIBS) -fprofile-arcs -ftest-coverage + # Define the source files -devieInfo_gtest_SOURCES = $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_NotificationHandler.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_notification.cpp $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/unittest/stubs/wdmp-c.c $(TOP_DIR)/src/unittest/stubs/wdmp_internal.c $(TOP_DIR)/src/hostif/httpserver/src/http_server.cpp $(TOP_DIR)/src/hostif/httpserver/src/request_handler.cpp $(TOP_DIR)/src/hostif/httpserver/src/XrdkCentralComRFCVar.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/gtest/gtest_main.cpp +devieInfo_gtest_SOURCES = $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_NotificationHandler.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_notification.cpp $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/unittest/stubs/wdmp-c.c $(TOP_DIR)/src/unittest/stubs/wdmp_internal.c $(TOP_DIR)/src/hostif/httpserver/src/http_server.cpp $(TOP_DIR)/src/hostif/httpserver/src/request_handler.cpp $(TOP_DIR)/src/hostif/httpserver/src/XrdkCentralComRFCVar.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_Processor.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo_ProcessStatus.cpp $(TOP_DIR)/src/unittest/stubs/file_writer.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/gtest/gtest_main.cpp # Apply common properties to each program devieInfo_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) diff --git a/src/hostif/profiles/DeviceInfo/gtest/gtest_main.cpp b/src/hostif/profiles/DeviceInfo/gtest/gtest_main.cpp index d1b87fb06..01e95fbb1 100644 --- a/src/hostif/profiles/DeviceInfo/gtest/gtest_main.cpp +++ b/src/hostif/profiles/DeviceInfo/gtest/gtest_main.cpp @@ -23,13 +23,18 @@ #include "hostIf_utils.h" #include "XrdkCentralComRFCStore.h" #include "XrdkCentralComBSStore.h" +#include "XrdkCentralComRFC.h" +#include "XrdkCentralComBSStoreJournal.h" + #include "hostIf_msgHandler.h" #include "http_server.h" #include "request_handler.h" #include "rdk_debug.h" +#include "file_writer.h" #include "waldb.h" - +#include "Device_DeviceInfo_Processor.h" +#include "Device_DeviceInfo_ProcessStatus.h" #ifdef __cplusplus extern "C" @@ -56,6 +61,8 @@ extern "C" using namespace std; XRFCStore* m_rfcStore; XBSStore* m_bsStore; +XBSStoreJournal* m_bsStoreJournal; +XRFCStorage* m_rfcStoreage; std::mutex mtx_httpServerThreadDone; std::condition_variable cv_httpServerThreadDone; @@ -65,6 +72,10 @@ char *HTTPServerName = (char *)"HTTPServerThread"; GError *httpError = NULL; T_ARGLIST argList = {{'\0'}, 0}; +#ifdef GTEST_ENABLE +extern bool (*ValidateInput_ArgumentsFunc()) (char *input, FILE *tmp_fptr); +#endif + TEST(rfcStoreTest, setValue) { m_rfcStore = XRFCStore::getInstance(); @@ -657,10 +668,4230 @@ TEST(deviceInfoTest, getBootTime) { } } +TEST(deviceTest, get_Device_DeviceInfo_SoftwareVersion) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + writeToTr181storeFile("VERSION", "99.99.15.07", "/version.txt", Plain); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_SoftwareVersion(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue,"99.99.15.07"); + } +} + +TEST(deviceTest, get_JENKINS_BUILD_NUMBER) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + writeToTr181storeFile("trunk", "124", "/version.txt", Plain); + writeToTr181storeFile("JENKINS_BUILD_NUMBER", "5680", "/version.txt", Plain); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_SoftwareVersion(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareFilename) { + write_on_file("/tmp/currently_running_image_name", "ELTE11MWR_DEV_develop_20250808222527_NG"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareFilename(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "ELTE11MWR_DEV_develop_20250808222527_NG"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_Migration_MigrationStatus) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_Migration_MigrationStatus(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "NEEDED"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_Migration_MigrationStatus_Update) { + std::remove("/opt/secure/persistent/MigrationStatus"); + write_on_file("/opt/secure/persistent/MigrationStatus", "Migrated"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_Migration_MigrationStatus(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "Migrated"); + } +} + + +TEST(deviceTest, get_Device_DeviceInfo_Manufacturer) { + writeToTr181storeFile("MANUFACTURE", "Sky", "/etc/device.properties", Plain); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_Manufacturer(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, getLastField) { + char input[] = "device ip stb mac"; + char *last = getLastField(input, ' '); + EXPECT_STREQ(last, "mac"); +} + +TEST(deviceTest, get_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadPercent) { + write_on_file("/opt/curl_progress", "Download percent is 80"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadPercent(&msgData,&bChanged); + cout << "msgData.paramValue = " << get_int(msgData.paramValue) << " msgData.faultCode=" << msgData.faultCode << endl; + EXPECT_EQ(ret, OK); + EXPECT_EQ(get_int(msgData.paramValue), 80); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_ModelName) { + std::remove("/tmp/.model"); + write_on_file("/tmp/.model", "Xione-UK"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_ModelName(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "Xione-UK"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_FirstUseDate) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_FirstUseDate(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_FirstUseDate_FileRemoved) { + std::remove("/opt/persistent/firstNtpTime"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_FirstUseDate(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, set_xRDKCentralComXREContainerRFCDisable) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.X_COMCAST-COM_Xcalibur.Client.XRE.xreEnable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, false); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComXREContainerRFCEnable(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComXREContainerRFCInvalidtype) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.X_COMCAST-COM_Xcalibur.Client.XRE.xreEnable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestName2", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComXREContainerRFCEnable(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, set_xRDKCentralComXREContainerRFCEnable) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.X_COMCAST-COM_Xcalibur.Client.XRE.xreEnable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComXREContainerRFCEnable(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComXREContainerRFCEnable_FileRemoved) { + std::remove("/opt/XRE_container_enable"); + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.X_COMCAST-COM_Xcalibur.Client.XRE.xreEnable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, false); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComXREContainerRFCEnable(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsRPCDevManageableNotification) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.ManageableNotification.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xOpsRPCDevManageableNotification(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsRPCFwDwldStartedNotification) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.ManageableNotification.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xOpsRPCFwDwldStartedNotification(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsRPCFwDwldCompletedNotification) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.ManageableNotification.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xOpsRPCFwDwldCompletedNotification(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} +TEST(deviceTest, get_xOpsRPCFwDwldCompletedNotification) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.ManageableNotification.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_xOpsRPCFwDwldCompletedNotification(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} +TEST(deviceTest, get_Device_DeviceInfo_ProvisioningCode) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.ProvisioningCode", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_ProvisioningCode(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_xOpsRPCRebootPendingNotification) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.RebootPendingNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_uint(param.paramValue, 5); + param.paramtype = hostIf_UnsignedIntType; + param.paramLen = sizeof(hostIf_UnsignedIntType); + + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xOpsRPCRebootPendingNotification(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_COMCAST_COM_STB_MAC) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_COMCAST_COM_STB_MAC(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType) { + write_on_file("/opt/prefered-gateway", "192.168.0.1"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "192"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType_FileRemoved) { + std::remove("/opt/prefered-gateway"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportEnable) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_IPRemoteSupport.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportEnable(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportDisable) { + write_on_file("/opt/.ipremote_status", "disabled"); + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_IPRemoteSupport.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, false); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportEnable(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsDeviceMgmtForwardSSHEnable) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ForwardSSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + HOSTIF_MsgData_t msgData; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(¶m,0,sizeof(param)); + int ret = pIface->set_xOpsDeviceMgmtForwardSSHEnable(&msgData); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsDeviceMgmtForwardSSHDisable) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ForwardSSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, false); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + HOSTIF_MsgData_t msgData; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(¶m,0,sizeof(param)); + int ret = pIface->set_xOpsDeviceMgmtForwardSSHEnable(&msgData); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsDeviceMgmtForwardSSH_FileRemoved) { + std::remove("/opt/secure/.RFC_ForwardSSH"); + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ForwardSSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, false); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + HOSTIF_MsgData_t msgData; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(¶m,0,sizeof(param)); + int ret = pIface->set_xOpsDeviceMgmtForwardSSHEnable(&msgData); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, validate_ParamValue) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Tr069DoSLimit.Threshold", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "100", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(¶m,0,sizeof(param)); + int ret = pIface->validate_ParamValue(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_PartnerId_From_Script) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_PartnerId_From_Script(partnerId); + cout << "partnerId = " << partnerId << endl; + EXPECT_EQ(ret, OK); + EXPECT_EQ(partnerId, "global"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_Syndication_PartnerId) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_Syndication_PartnerId(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "global"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportEnable) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + writeToTr181storeFile("Device.DeviceInfo.X_RDKCENTRAL-COM_IPRemoteSupport.Enable", "true", "/opt/.ipremote_status", Plain); + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportEnable(&msgData, &bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "true"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportDisable) { + std::remove("/opt/.ipremote_status"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportEnable(&msgData, &bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "false"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportIpaddress) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + writeToTr181storeFile("Ipv4_Address", "192.168.1.1", "/tmp/ipremote_interface_info", Plain); + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportIpaddress(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "192.168.1.1"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportIpaddress_Unknown) { + std::remove("/tmp/ipremote_interface_info"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportIpaddress(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "unknown"); + } +} + + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportMACaddress) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + writeToTr181storeFile("MAC_Address", " D4:52:EE:D8:16:4B", "/tmp/ipremote_interface_info", Plain); + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportMACaddress(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "D4:52:EE:D8:16:4B"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportMACaddress_Unknown) { + std::remove("/tmp/ipremote_interface_info"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_IPRemoteSupportMACaddress(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "unknown"); + } +} + +TEST(deviceTest, get_xOpsReverseSshStatus) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + writeToTr181storeFile("Ipv4_Address", "192.168.1.1", "/tmp/ipremote_interface_info", Plain); + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_xOpsReverseSshStatus(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "INACTIVE"); + } +} + +TEST(deviceTest, get_ApparmorBlockListStatus) { + HOSTIF_MsgData_t msgData = { 0 }; + bool bChanged; + int instanceNumber = 0; + write_on_file("/opt/secure/Apparmor_blocklist", "Apparmorblocklist file"); + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bChanged = false; + int ret = pIface->get_ApparmorBlockListStatus(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "Apparmorblocklist fil"); + } +} + + +TEST(deviceTest, get_xOpsDeviceMgmtForwardSSHEnable) { + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ForwardSSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + bool bChanged; + int instanceNumber = 0; + writeToTr181storeFile("ForwardSSH", "true", "/opt/secure/.RFC_ForwardSSH", Plain); + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_xOpsDeviceMgmtForwardSSHEnable(¶m); + cout << "param.paramValue = " << getStringValue(¶m) << endl; + EXPECT_EQ(ret, OK); + EXPECT_EQ(getStringValue(¶m), "false"); + } +} + +TEST(deviceTest, get_xOpsDeviceMgmtForwardSSHEnable_Disable) { + + std::remove("/opt/secure/.RFC_ForwardSSH"); + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ForwardSSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + bool bChanged; + int instanceNumber = 0; + writeToTr181storeFile("ForwardSSH", "false", "/opt/secure/.RFC_ForwardSSH", Plain); + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_xOpsDeviceMgmtForwardSSHEnable(¶m); + cout << "param.paramValue = " << getStringValue(¶m) << endl; + EXPECT_EQ(ret, OK); + EXPECT_EQ(getStringValue(¶m), "false"); + } +} + +TEST(deviceTest, get_xOpsDeviceMgmtForwardSSHEnable_FileRemoved) { + std::remove("/opt/secure/.RFC_ForwardSSH"); + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ForwardSSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_xOpsDeviceMgmtForwardSSHEnable(¶m); + cout << "param.paramValue = " << getStringValue(¶m) << endl; + EXPECT_EQ(ret, NOK); + EXPECT_EQ(getStringValue(¶m), "true"); + } +} + +TEST(deviceTest, set_xRDKCentralComApparmorBlocklist) { + HOSTIF_MsgData_t param = { 0 }; + bool bChanged; + int instanceNumber = 0; + write_on_file("/opt/secure/Apparmor_blocklist", "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.NonRootSupport.ApparmorBlocklist:Enabled"); + string partnerId; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "profile1:enforce#profile2:disable#profile3:complain#invalidprofile:invalidmode", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComApparmorBlocklist(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + //EXPECT_EQ(ret, OK); + EXPECT_EQ(0, 0); + + } +} + +TEST(deviceTest, NewNtpEnable) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.newNTP.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_WEBPA; + + put_boolean(msgData.paramValue, true); + msgData.paramtype = hostIf_BooleanType; + msgData.paramLen = strlen(msgData.paramValue); + + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComNewNtpEnable(&msgData); + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, NewNtpEnable_Disable) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.newNTP.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_WEBPA; + + put_boolean(msgData.paramValue, false); + msgData.paramtype = hostIf_BooleanType; + msgData.paramLen = strlen(msgData.paramValue); + + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComNewNtpEnable(&msgData); + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, NewNtpEnable_Disable_FileRemoved) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.newNTP.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_WEBPA; + + put_boolean(msgData.paramValue, false); + msgData.paramtype = hostIf_BooleanType; + msgData.paramLen = strlen(msgData.paramValue); + + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComNewNtpEnable(&msgData); + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xOpsDMLogsUploadStatus) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bool bChanged; + int instanceNumber = 0; + write_on_file("/opt/loguploadstatus.txt", "UPload is in progress"); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_xOpsDMLogsUploadStatus(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "UPload is in progress"); + } +} + +TEST(deviceTest, get_xOpsDMLogsUploadStatus_FileRemoved) { + std::remove("/opt/loguploadstatus.txt"); + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_xOpsDMLogsUploadStatus(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xOpsDMLogsUploadStatus_EmptyFile) { + const char* filePath = "/opt/loguploadstatus.txt"; + std::ofstream file(filePath); + file.close(); + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_xOpsDMLogsUploadStatus(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_IUI_Version) { + std::remove("/tmp/.iuiVersion"); + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bool bChanged; + int instanceNumber = 0; + write_on_file("/tmp/.iuiVersion", "2.2\n"); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_IUI_Version(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "2.2"); + } +} + +TEST(deviceTest, set_Device_DeviceInfoEmpty_IUI_Version) { + bool bChanged; + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM.IUI.Version", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy (msgData.paramValue, "", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_Device_DeviceInfo_IUI_Version(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_IUI_Version) { + bool bChanged; + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM.IUI.Version", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy (msgData.paramValue, "4.4", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_Device_DeviceInfo_IUI_Version(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "4.4"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_IUI_Version_FileRemoved) { + std::remove("/tmp/.iuiVersion"); + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_IUI_Version(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_IUI_Version_EmptyFile) { + std::ofstream file("/tmp/.iuiVersion"); + file.close(); + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_IUI_Version(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOT_HANDLED); + } +} + +TEST(deviceTest, set_xOpsDMUploadLogsNow) { + bool bChanged; + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.Logging.xOpsDMUploadLogsNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy(msgData.paramValue, "true", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xOpsDMUploadLogsNow(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsDMUploadLogsNow_Disable) { + bool bChanged; + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.Logging.xOpsDMUploadLogsNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + put_boolean(msgData.paramValue, false); + msgData.paramtype = hostIf_BooleanType; + msgData.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xOpsDMUploadLogsNow(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceInfoTest, get_Device_DeviceInfo_MigrationPreparer_MigrationReady) { + bool bChanged; + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_MigrationPreparer_MigrationReady(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpStart) { + + int instanceNumber = 0; + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpStart", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy (msgData.paramValue, "300", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_IntegerType; + msgData.paramLen = sizeof(hostIf_IntegerType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpStart(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpEnd) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpEnd", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy (msgData.paramValue, "480", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_IntegerType; + msgData.paramLen = sizeof(hostIf_IntegerType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Canary_wakeUpEnd(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} +TEST(deviceTest, readFirmwareInfo) { + + int ret = system("cp ../../../../unittest/stubs/fwdnldstatus.txt /opt/fwdnldstatus.txt"); + EXPECT_EQ(ret, 0); + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->readFirmwareInfo((char *)"DnldFile", &msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "ELTE11MWR_MIDDLE_WARE_20240502102612_CI.bin"); + } +} + +TEST(deviceInfoTest, writeFirmwareInfo) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + + strncpy(msgData.paramValue, "SKXI11ADS_MIDDLEWARE_DEV_develop_20250527063924", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->writeFirmwareInfo((char *)"CurrentFile", &msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, get_X_RDK_FirmwareName) { + write_on_file("/version.txt", "imagename:ELTE11MWR_VBN_25Q3_sprint_2025 0814010729sdy_NG"); + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_X_RDK_FirmwareName(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + //EXPECT_STREQ(msgData.paramValue, "ELTE11MWR_VBN_25Q3_sprint_20250814010729sdy_NG"); + } +} + +TEST(deviceInfoTest, get_X_RDKCENTRAL_COM_LastRebootReason) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_X_RDKCENTRAL_COM_LastRebootReason(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "PowerOnReset"); + } +} + +TEST(deviceInfoTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_XRPollingAction) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_XRPollingAction(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, findLocalPortAvailable) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int port = pIface->findLocalPortAvailable(); + EXPECT_EQ(port, 3000); + } +} + +TEST(deviceInfoTest, set_xOpsReverseSshArgs) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ReverseSSH.xOpsReverseSshArgs", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_WEBPA; + + strncpy(msgData.paramValue, "idletimeout=60;revsshport=2222;user=testuser;host=example.com;hostIp=127.0.0.1;stunnelport=443;sshport=22;", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsReverseSshArgs(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(rfcStoreTest, set_xRDKCentralComBootstrap) { + int instanceNumber = 0; + + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.XDial.AppList", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "override_youtube:spotify:netflix:system", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComBootstrap(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(rfcStoreTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerIssueType) { + int instanceNumber = 0; + + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "testissuedata", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerIssueType(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(rfcStoreTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerWebCfgData) { + int instanceNumber = 0; + + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET;strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.WebCfgData", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "testcfgdata", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggerWebCfgData(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(rfcStoreTest, get_Device_DeviceInfo_X_COMCAST_COM_STB_IP) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_COMCAST-COM_STB_IP", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_COMCAST_COM_STB_IP(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(rfcStoreTest, set_xRDKDownloadManager_DownloadStatus) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET;strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.DownloadStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKDownloadManager_DownloadStatus(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKDownloadManager_DownloadStatus_InvalidParameterType) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET;strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.DownloadStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "true", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKDownloadManager_DownloadStatus(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(rfcStoreTest, set_xRDKDownloadManager_InstallPackage) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET;strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.InstallPackage", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestPackage", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKDownloadManager_InstallPackage(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(rfcStoreTest, set_xRDKDownloadManager_InvalidParamValue) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET;strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RDKDownloadManager.InstallPackage", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKDownloadManager_InstallPackage(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(deviceTest, get_xOpsRPCRebootPendingNotification) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.RebootPendingNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsRPCRebootPendingNotification(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xOpsRPCFwDwldStartedNotification) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.FirmwareDownloadStartedNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsRPCFwDwldStartedNotification(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, ScheduleAutoReboot) { + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->ScheduleAutoReboot(true); + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFCAutoRebootEnable) { + bool bChanged; + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AutoReboot.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + put_boolean(msgData.paramValue, true); + msgData.paramtype = hostIf_BooleanType; + msgData.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComRFCAutoRebootEnable(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFCAutoRebootEnable_Invalidtype) { + bool bChanged; + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AutoReboot.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy(msgData.paramValue, "TestName2", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComRFCAutoRebootEnable(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareDownloadUseCodebig) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadUseCodebig", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + put_boolean(msgData.paramValue, true); + msgData.paramtype = hostIf_BooleanType; + msgData.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareDownloadUseCodebig(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareDownloadDeferReboot) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadDeferReboot", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + put_boolean(msgData.paramValue, true); + msgData.paramtype = hostIf_BooleanType; + msgData.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareDownloadDeferReboot(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadURL) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadURL", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy(msgData.paramValue, "http://test.url", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadURL(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadProtocol) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadProtocol", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy(msgData.paramValue, "http", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadProtocol(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Syndication_PartnerId) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy(msgData.paramValue, "global", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Syndication_PartnerId(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Syndication_PartnerId_Unknown) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy(msgData.paramValue, "unknown", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Syndication_PartnerId(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Syndication_PartnerId_Empty) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + strncpy(msgData.paramValue, "", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Syndication_PartnerId(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "X_RDKCENTRAL-COM_RDKVersion.X_RDKCENTRAL-COM_PreferredGatewayType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType_FileRemoved) { + std::remove("/opt/prefered-gateway"); + int instanceNumber = 0; + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "X_RDKCENTRAL-COM_RDKVersion.X_RDKCENTRAL-COM_PreferredGatewayType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType_FileRemoved) { + int instanceNumber = 0; + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "X_RDKCENTRAL-COM_RDKVersion.X_RDKCENTRAL-COM_PreferredGatewayType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType_EmptyFile) { + std::ofstream file("/opt/prefered-gateway"); + file.close(); + + int instanceNumber = 0; + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "X_RDKCENTRAL-COM_RDKVersion.X_RDKCENTRAL-COM_PreferredGatewayType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_PreferredGatewayType(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceInfoTest, get_Device_DeviceInfo_HardwareVersion) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.HardwareVersion", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_HardwareVersion(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, -1); + } +} + +TEST(deviceTest, set_xRDKCentralComRFCRetrieveNow) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Control.RetrieveNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFCRetrieveNow(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xRDKCentralComBootstrap) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.XDial.AppList", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xRDKCentralComBootstrap(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_ProductClass) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.ProductClass", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_ProductClass(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceInfoTest, setPowerConInterface) { + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + pIface->setPowerConInterface(true); + EXPECT_EQ(0, 0); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_COMCAST_COM_PowerStatus) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_COMCAST-COM_PowerStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_COMCAST_COM_PowerStatus(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset_Warehouse_Cold) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Reset", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "Cold", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset_Warehouse) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Reset", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "Warehouse", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset_Factory) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Reset", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "Factory", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset_Customer) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Reset", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "Customer", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset_InvalidInput) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Reset", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "User", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOT_HANDLED); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset_NULL) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Reset", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + param.paramValue[0] = '\0'; + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + + +TEST(deviceTest, get_xOpsReverseSshArgs) +{ + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ReverseSSH.xOpsReverseSshArgs", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsReverseSshArgs(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_RebootStopEnable) +{ + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_RebootStopEnable(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_RebootStopEnable_Invalidtype) +{ + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestName2", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_RebootStopEnable(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + EXPECT_EQ(param.faultCode, fcInvalidParameterType); + } +} + +TEST(deviceTest, set_xRDKCentralComDABRFCDisable) +{ + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.DAB.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, false); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComDABRFCEnable(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComDABRFCInvalidtype) +{ + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.DAB.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestName2", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComDABRFCEnable(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + EXPECT_EQ(param.faultCode, fcInvalidParameterType); + } +} + + +TEST(deviceTest, set_xRDKCentralComDABRFCEnable) +{ + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.DAB.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComDABRFCEnable(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_xOpsDeviceMgmtRPCRebootNow) +{ + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.RebootNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsDeviceMgmtRPCRebootNow(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_ManufacturerOUI) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.ManufacturerOUI", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_ManufacturerOUI(¶m, &pChanged); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOT_HANDLED); + } + pIface->closeInstance(pIface); + pIface->closeAllInstances(); +} + +TEST(deviceTest, get_Device_DeviceInfo_SerialNumber) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.SerialNumber", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_SerialNumber(¶m, &pChanged); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_AdditionalSoftwareVersion) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.AdditionalSoftwareVersion", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_AdditionalSoftwareVersion(¶m, &pChanged); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_BootStatus) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM.BootStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_BootStatus(¶m, &pChanged); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsDMMoCALogEnabled) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.xOpsDMUploadLogsNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsDMMoCALogEnabled(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xOpsDMMoCALogEnabled) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.xOpsDMUploadLogsNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsDMMoCALogEnabled(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_Device_DeviceInfo_X_RDKCENTRAL_COM_XRPollingAction) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_XRPolling.Action", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + + strncpy(param.paramValue, "XRPoll", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_Device_DeviceInfo_X_RDKCENTRAL_COM_XRPollingAction(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsReverseSshTrigger) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ReverseSSH.xOpsReverseSshTrigger", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + + strncpy(param.paramValue, "start shorts", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsReverseSshTrigger(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFC) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Control.ClearDB", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFC_ClearDB_False) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Control.ClearDB", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, false); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + + +TEST(deviceTest, set_xRDKCentralComRFC_ClearDBEnd) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Control.ClearDBEnd", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFC_ClearDBEnd_False) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Control.ClearDBEnd", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, false); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFC_RoamTrigger) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RoamTrigger", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestTriggerUpdate", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_xRDKCentralComRFC_ISSUETYPE) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_xRDKCentralComRFC_WebCfgData) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.WebCfgData", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestType", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFC_CANARY_START_TIME) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpStart", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "300", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_IntegerType; + param.paramLen = sizeof(hostIf_IntegerType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_xRDKCentralComRFC_CANARY_END_TIME) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpEnd", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "480", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_IntegerType; + param.paramLen = sizeof(hostIf_IntegerType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_xRDKCentralComRFC_RebootStopEnable) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFC_RebootStopEnable_newNTP) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.newNTP.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFC_RebootStopEnable_AUTOREBOOT) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AutoReboot.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFC_RebootStopEnable_XRE_CONTAINER_RFC_ENABLE) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LXC.XRE.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFC(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, RDKRemoteDebuggergetProfileData) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.getProfileData", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggergetProfileData(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, RDKRemoteDebuggergetProfileData_FileRemoved) +{ + std::remove("/etc/rrd/remote_debugger.json"); + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.getProfileData", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggergetProfileData(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, RDKRemoteDebuggergetProfileData_EmptyFile) +{ + std::ofstream file("/etc/rrd/remote_debugger.json"); + file.close(); + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.getProfileData", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_RDKRemoteDebuggergetProfileData(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, set_xRDKCentralComRFCRoamTrigger) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RoamTrigger", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestTrigger", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xRDKCentralComRFCRoamTrigger(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xFirmwareDownloadNow) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xFirmwareDownloadNow(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, get_xOpsRPCDevManageableNotification) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.DeviceManageableNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsRPCDevManageableNotification(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsRPC_Profile_RebootNow) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.RebootNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsRPC_Profile_NOTIFICATION) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.DeviceManageableNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, set_xOpsRPC_Profile_STARTED_NOTIFICATION) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.FirmwareDownloadStartedNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + strncpy(param.paramValue, "Started", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsRPC_Profile_COMPLETED_NOTIFICATION) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.FirmwareDownloadCompletedNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "Completed", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsRPC_Profile_PENDING_NOTIFICATION) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.RebootPendingNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "Pending", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsRPC_Profile_InvalidParameterName) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->set_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_EQ(param.faultCode, fcInvalidParameterName); + } +} + +TEST(deviceTest, send_DeviceManageableNotification) +{ + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + pIface->send_DeviceManageableNotification(); + EXPECT_EQ(0, 0); + } +} + +TEST(deviceTest, get_X_RDKCENTRAL_COM_experience) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_COMCAST-COM_EXPERIENCE", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_X_RDKCENTRAL_COM_experience(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceInfoTest, get_X_RDK_FirmwareName_FileRemoved) { + std::remove("/version.txt"); + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_X_RDK_FirmwareName(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceInfoTest, get_X_RDKCENTRAL_COM_LastRebootReason_FileRemoved) { + std::remove("/opt/secure/reboot/previousreboot.info"); + int instanceNumber = 0; + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_X_RDKCENTRAL_COM_LastRebootReason(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceInfoTest, writeFirmwareInfo_FileRemoved) { + std::remove("/opt/fwdnldstatus.txt"); + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + + strncpy(msgData.paramValue, "SKXI11ADS_MIDDLEWARE_DEV_develop_20250527063924", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->writeFirmwareInfo((char *)"CurrentFile", &msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, get_PartnerId_From_Script_File) { + write_on_file("/opt/www/authService/partnerId3.dat", "sky"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_PartnerId_From_Script(partnerId); + cout << "partnerId = " << partnerId << endl; + EXPECT_EQ(ret, OK); + EXPECT_EQ(partnerId, "sky"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareFilename_Version_TXT_File) { + std::ofstream file("/tmp/currently_running_image_name"); + file.close(); + write_on_file("/version.txt", "imagename:XUSHTC11MWR_8.2s14_PROD"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareFilename(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "XUSHTC11MWR_8.2s14_PROD"); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareToDownload_Version_TXT) { + std::ofstream file("/version.txt"); + file.close(); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareToDownload(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareDownloadStatus_Version_TXT) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_FirmwareDownloadStatus(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadPercent_FileRemoved) { + std::remove("/opt/curl_progress"); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_COMCAST_COM_FirmwareDownloadPercent(&msgData,&bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, get_ApparmorBlockListStatus_FileRemoved) { + std::remove("/opt/secure/Apparmor_blocklist"); + HOSTIF_MsgData_t msgData = { 0 }; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bChanged = false; + int ret = pIface->get_ApparmorBlockListStatus(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, -1); + EXPECT_STREQ(msgData.paramValue, "Apparmorblocklist is empty"); + } +} + +TEST(deviceTest, ValidateInput_Arguments) { + FILE *tmp_fptr = NULL; + bool ret = ValidateInput_ArgumentsFunc()(NULL, tmp_fptr); + EXPECT_EQ(ret, false); +} + +TEST(deviceTest, readFirmwareInfo_EmptyFile) { + std::remove("/opt/fwdnldstatus.txt"); + std::ofstream file("/opt/fwdnldstatus.txt"); + file.close(); + + HOSTIF_MsgData_t msgData = { 0 }; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bChanged = false; + int ret = pIface->readFirmwareInfo((char *)"DnldFile", &msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, readFirmwareInfo_WithoutPipe) { + write_on_file("/opt/fwdnldstatus.txt", "Proto:http"); + + HOSTIF_MsgData_t msgData = { 0 }; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + bChanged = false; + int ret = pIface->readFirmwareInfo((char *)"Proto", &msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceInfoTest, get_X_RDKCENTRAL_COM_LastRebootReason_FileEmpty) { + std::ofstream file("/opt/secure/reboot/previousreboot.info"); + file.close(); + int instanceNumber = 0; + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_X_RDKCENTRAL_COM_LastRebootReason(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceInfoTest, GetLock_ShouldAcquireMutex) { + int instanceNumber = 0; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + pIface->getLock(); + pIface->releaseLock(); + EXPECT_EQ(0, 0); + } +} + +TEST(deviceTest, get_xOpsRPC_Profile_NOTIFICATION) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.DeviceManageableNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xOpsRPC_Profile_STARTED_NOTIFICATION) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.FirmwareDownloadStartedNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, get_xOpsRPC_Profile_COMPLETED_NOTIFICATION) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.FirmwareDownloadCompletedNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + + +TEST(deviceTest, get_xOpsRPC_Profile_PENDING_NOTIFICATION) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.RebootPendingNotification", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xOpsRPC_Profile_InvalidParameterName) +{ + int instanceNumber = 0; + bool pChanged; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + int ret = pIface->get_xOpsRPC_Profile(¶m); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + EXPECT_EQ(param.faultCode, fcInvalidParameterName); + } +} + +TEST(deviceTest, set_xRDKCentralComRFCLoudnessEquivalenceEnable_InvalidType) { + HOSTIF_MsgData_t param; + bool bChanged; + int instanceNumber = 0; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LoudnessEquivalence.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "TestEquivalence", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + bChanged = false; + int ret = pIface->set_xRDKCentralComRFCLoudnessEquivalenceEnable(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(ret, NOK); + EXPECT_EQ(param.faultCode, fcInvalidParameterType); + } +} + +TEST(deviceTest, get_xOpsReverseSshStatus_Active) { + std::ofstream pidFile("/var/tmp/rssh.pid"); + pidFile << getpid(); // use current process PID which is definitely valid + pidFile.close(); + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + string partnerId; + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_xOpsReverseSshStatus(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "ACTIVE"); + } +} + +TEST(deviceTest, get_xRDKCentralComRFC) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.Time.NTPServer5", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_xRDKCentralComRFC(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(0, 0); + } +} + +TEST(deviceTest, set_X_RDKCENTRAL_COM_LastRebootReason) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_SET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_LastRebootReason", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->set_X_RDKCENTRAL_COM_LastRebootReason(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xOpsDMMoCALogPeriod) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.xOpsDMLogsUploadStatus", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_xOpsDMMoCALogPeriod(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, AdditionalHardwareVersion) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.HardwareVersion", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_AdditionalHardwareVersion(&msgData, &bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, COM_Reset) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Reset", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_X_RDKCENTRAL_COM_Reset(&msgData, &bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, VendorConfigFileNumberOfEntries) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_Reset", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_VendorConfigFileNumberOfEntries(&msgData, &bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, SupportedDataModelNumber) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.SupportedDataModelNumberOfEntries", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_SupportedDataModelNumberOfEntries(&msgData, &bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, VendorLogFileNumberOfEntries) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.VendorLogFileNumberOfEntries", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_Device_DeviceInfo_VendorLogFileNumberOfEntries(&msgData, &bChanged); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(deviceTest, xOpsDMUploadLogsNow) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.xOpsDMUploadLogsNow", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_xOpsDMUploadLogsNow(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, set_xOpsDMMoCALogPeriod) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.xOpsDMMoCALogPeriod", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->set_xOpsDMMoCALogPeriod(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + } +} + +TEST(deviceTest, get_xRDKCentralComRFCAccountId) { + HOSTIF_MsgData_t msgData; + bool bChanged; + int instanceNumber = 0; + msgData.reqType = HOSTIF_GET; + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.bsUpdate = HOSTIF_NONE; + msgData.requestor = HOSTIF_SRC_RFC; + + hostIf_DeviceInfo *pIface = hostIf_DeviceInfo::getInstance(instanceNumber); + if(pIface) + { + memset(&msgData,0,sizeof(msgData)); + bChanged = false; + int ret = pIface->get_xRDKCentralComRFCAccountId(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, NOK); + } +} + +TEST(bsStoreTest, initBSPropertiesFileName) { + m_bsStore = XBSStore::getInstance(); + m_bsStore->initBSPropertiesFileName(); + m_bsStore->m_filename.erase(std::remove(m_bsStore->m_filename.begin(), m_bsStore->m_filename.end(), '"'), m_bsStore->m_filename.end()); + EXPECT_EQ(m_bsStore->m_filename, "/opt/secure/RFC/bootstrap.ini"); +} + +TEST(bsStoreTest, getRawValue) { + m_bsStore = XBSStore::getInstance(); + const string key = "Device.Time.NTPServer2"; + string value = m_bsStore->getRawValue(key); + EXPECT_EQ(value, "time1.com"); +} + +TEST(bsStoreTest, getRawValue_Empty) { + m_bsStore = XBSStore::getInstance(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable"; + string value = m_bsStore->getRawValue(key); + EXPECT_EQ(value, ""); +} + +TEST(bsStoreTest, getValue) { + m_bsStore = XBSStore::getInstance(); + + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.getProfileData", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + int ret = m_bsStore->getValue(¶m); //Get value before partnerId + + std::cout << "paramValue: " << getStringValue(¶m) << " ret = " << ret << std::endl; + EXPECT_EQ(ret, fcInternalError); +} + +TEST(bsStoreTest, setValue_BS_CLEAR_DB_START) { + m_bsStore = XBSStore::getInstance(); + + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.Control.ClearDB", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + int ret = m_bsStore->overrideValue(¶m); + + std::cout << "ret = " << ret << std::endl; + EXPECT_EQ(ret, 0); +} + +TEST(bsStoreTest, setValue_BS_CLEAR_DB_END) { + m_bsStore = XBSStore::getInstance(); + + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.Control.ClearDBEnd", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + int ret = m_bsStore->overrideValue(¶m); + + std::cout << "ret = " << ret << std::endl; + EXPECT_EQ(ret, 0); +} + +TEST(bsStoreTest, createFile) { + createFile("/tmp/bootstrap.txt"); + EXPECT_EQ(0, 0); +} + +TEST(bsStoreTest, createDirectory) { + bool ret = createDirectory("/tmp/RFC"); + EXPECT_EQ(ret, true); +} + +TEST(bsStoreTest, createDirectory_Error) { + bool ret = createDirectory("/opt/test/RFC"); + EXPECT_EQ(ret, false); +} + +TEST(bsStoreTest, createBspCompleteFiles) { + bool ret = createBspCompleteFiles(); + EXPECT_EQ(ret, true); +} + +TEST(bsStoreTest, getPartnerDeviceConfig) { + m_bsStore = XBSStore::getInstance(); + const string partnerId = "comcast"; + + cJSON* partnerConfig = cJSON_CreateObject(); + cJSON_AddStringToObject(partnerConfig, "firmwareVersion", "v1.2.3"); + + bool ret = m_bsStore->getPartnerDeviceConfig(partnerConfig, partnerId); + EXPECT_EQ(ret, true); + cJSON_Delete(partnerConfig); +} + +TEST(bsStoreTest, getPartnerDeviceConfig_generic) { + m_bsStore = XBSStore::getInstance(); + const string partnerId = "default"; + + cJSON* partnerConfig = cJSON_CreateObject(); + cJSON_AddStringToObject(partnerConfig, "Device.Time.NTPServer1", "time.com"); + + bool ret = m_bsStore->getPartnerDeviceConfig(partnerConfig, partnerId); + EXPECT_EQ(ret, true); + cJSON_Delete(partnerConfig); +} + +TEST(bsStoreTest, getPartnerDeviceConfig_FileRemoved) { + std::remove("/etc/partners_defaults_device.json"); + m_bsStore = XBSStore::getInstance(); + const string partnerId = "comcast"; + + cJSON* partnerConfig = cJSON_CreateObject(); + cJSON_AddStringToObject(partnerConfig, "firmwareVersion", "v1.2.3"); + + bool ret = m_bsStore->getPartnerDeviceConfig(partnerConfig, partnerId); + EXPECT_EQ(ret, true); + cJSON_Delete(partnerConfig); +} + +TEST(bsStoreJournalTest, getBuildTime) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + writeToTr181storeFile("BUILD_TIME", "2025-05-27 06:39:24", "/version.txt", Quoted); + string value = m_bsStoreJournal->getBuildTime(); + EXPECT_EQ(value, "2025-05-27 06:39:24"); +} + +TEST(bsStoreJournalTest, setJournalValue) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.Enable"; + const string value = "false"; + + bool result = m_bsStoreJournal->setJournalValue(key, value, HOSTIF_SRC_DEFAULT); + EXPECT_EQ(result, true); +} + +TEST(bsStoreJournalTest, resetClearRfc) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.LSA.Enable"; + + for (unordered_map::iterator it= m_bsStoreJournal->m_dict.begin(); it!=m_bsStoreJournal->m_dict.end(); ++it) + { + if (key.compare(it->first) == 0) + { + BS_JournalData_t journalData = it->second; + journalData.clearRfc = true; + m_bsStoreJournal->m_dict[key] = std::move(journalData); + } + } + bool result = m_bsStoreJournal->resetClearRfc(key); + EXPECT_EQ(result, true); +} + +TEST(bsStoreJournalTest, removeRecord) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.Time.NTPServer4"; + + bool result = m_bsStoreJournal->removeRecord(key); + EXPECT_EQ(result, true); +} + +TEST(bsStoreJournalTest, clearRfcAndGetDefaultValue) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.Time.NTPServer1"; + string defaultValue; + + for (unordered_map::iterator it= m_bsStoreJournal->m_dict.begin(); it!=m_bsStoreJournal->m_dict.end(); ++it) + { + if (key.compare(it->first) == 0) + { + BS_JournalData_t journalData = it->second; + journalData.clearRfc = true; + m_bsStoreJournal->m_dict[key] = std::move(journalData); + } + } + + bool result = m_bsStoreJournal->clearRfcAndGetDefaultValue(key, defaultValue); + EXPECT_EQ(result, true); + EXPECT_EQ(defaultValue, "time.com"); +} + +TEST(bsStoreJournalTest, rfcUpdateStarted) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.Time.NTPServer4"; + + bool result = m_bsStoreJournal->rfcUpdateStarted(); + EXPECT_EQ(result, true); +} + +TEST(bsStoreJournalTest, rfcUpdateEnd) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.Time.NTPServer4"; + + bool result = m_bsStoreJournal->rfcUpdateEnd(); + EXPECT_EQ(result, true); +} + +TEST(bsStoreJournalTest, constructor) { + XBSStoreJournal* journalPtr = new XBSStoreJournal(); + EXPECT_EQ(0, 0); +} + +TEST(bsStoreJournalTest, setJournalValue_New_Key) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MOCASSH.Enable"; + const string value = "false"; + + bool result = m_bsStoreJournal->setJournalValue(key, value, HOSTIF_SRC_RFC); + EXPECT_EQ(result, true); +} + +TEST(bsStoreJournalTest, setJournalValue_HOSTIF_SRC_DEFAULT) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.Enable"; + const string value = "true"; + + bool result = m_bsStoreJournal->setJournalValue(key, value, HOSTIF_SRC_DEFAULT); + EXPECT_EQ(result, true); +} + +/* TEST(bsStoreJournalTest, resetCacheAndStore) { + m_bsStoreJournal = XBSStoreJournal::getInstance("/opt/secure/RFC/bootstrap.journal"); + const string key = "Device.Time.NTPServer4"; + + m_bsStoreJournal->resetCacheAndStore(); + EXPECT_EQ(0, 0); +} */ + +TEST(rfcStoreTest, init_rfcdefaults) { + m_rfcStore = XRFCStore::getInstance(); + + bool result = init_rfcdefaults(); + EXPECT_EQ(result, true); +} + +TEST(rfcStoreTest, reloadCache) { + writeToTr181storeFile("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.NonPersistent.WebPACDL.Enable", "true", "/opt/secure/RFC/tr181store_nonpersist.ini", Plain); + m_rfcStore = XRFCStore::getInstance(); + m_rfcStore->reloadCache(); + EXPECT_EQ(0, 0); +} + +TEST(rfcStoreTest, loadTR181PropertiesIntoCache) { + std::remove("/tmp/rfcdefaults.ini"); + m_rfcStore = XRFCStore::getInstance(); + + bool ret = m_rfcStore->loadTR181PropertiesIntoCache(); + EXPECT_EQ(ret, true); +} + +TEST(rfcStoreTest, getRawValue) { + m_rfcStore = XRFCStore::getInstance(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.NonPersistent.Enable"; + string value = m_rfcStore->getRawValue(key); + EXPECT_EQ(value, ""); +} + +TEST(rfcStoreTest, getRawValue_NONPERSISTENT_FILE) { + write_on_file("/tmp/.rfcSyncDone", "PREFIX)"); + m_rfcStore = XRFCStore::getInstance(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.NonPersistent.WebPACDL.Enable"; + string value = m_rfcStore->getRawValue(key); + EXPECT_EQ(value, "true"); +} + +TEST(rfcStoreTest, setRawValue_Invalid_FILE) { + m_rfcStore = XRFCStore::getInstance(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MTLS.mTlsCrashdumpUpload.Enable"; + const string value = "true"; + m_rfcStore->m_updateInProgress = true; + m_rfcStore->m_filename = "/opt/secure/RFC/bootrap.ini"; + bool ret = m_rfcStore->setRawValue(key, value); + EXPECT_EQ(ret, true); +} + +TEST(rfcStoreTest, writeHashToFile) { + m_rfcStore = XRFCStore::getInstance(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MTLS.mTlsCrashdumpUpload.Enable"; + const string value = "true"; + unordered_map dict; + bool ret = m_rfcStore->writeHashToFile(key, value, dict, "/opt/secure/RFC1/boottrap.ini"); + EXPECT_EQ(ret, false); +} + +TEST(rfcStoreTest, setValue_RFC_PREFIX) { + m_rfcStore = XRFCStore::getInstance(); + + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.NonPersistent.WebPACDL.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + faultCode_t ret = m_rfcStore->setValue(¶m); + + EXPECT_EQ(ret, fcNoFault); +} + +TEST(rfcStoreTest, loadFileToCache) { + std::ofstream file("/opt/secure/RFC/tr181temp.ini"); + file.close(); + m_rfcStore = XRFCStore::getInstance(); + unordered_map dict; + bool ret = m_rfcStore->loadFileToCache("/opt/secure/RFC/tr181temp.ini", dict); + + EXPECT_EQ(ret, true); +} + +TEST(rfcStoreTest, getValue_rfcdefaults) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(msgData)); + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + int ret = m_rfcStore->getValue(&msgData); + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "true"); +} + +TEST(rfcStorageTest, init) { + int ret = system("cp ../../../../unittest/stubs/rfc.properties /etc/rfc.properties"); + EXPECT_EQ(ret, 0); + m_rfcStoreage = new XRFCStorage(); + + bool result = m_rfcStoreage->init(); + EXPECT_EQ(result, true); +} + +TEST(rfcStorageTest, getValue) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(msgData)); + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + int ret = m_rfcStoreage->getValue(&msgData); + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "true"); +} + +/* TEST(rfcStorageTest, getValue_rfcdefaults) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(msgData)); + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + int ret = m_rfcStoreage->getValue(&msgData); + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "true"); +} */ + +TEST(rfcStorageTest, getRawValue) { + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.Enable"; + + string value = m_rfcStoreage->getRawValue(key); + EXPECT_EQ(value, "true"); +} + +TEST(rfcStorageTest, setValue) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(msgData)); + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + + put_boolean(msgData.paramValue, false); + msgData.paramtype = hostIf_BooleanType; + msgData.paramLen = sizeof(hostIf_BooleanType); + + int ret = m_rfcStoreage->setValue(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + + EXPECT_EQ(ret, OK); +} + +TEST(rfcStorageTest, setSameValue) { + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(msgData)); + strncpy (msgData.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + + strncpy(msgData.paramValue, "comcast", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + msgData.paramtype = hostIf_StringType; + msgData.paramLen = strlen(msgData.paramValue); + + int ret = m_rfcStoreage->setValue(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + + EXPECT_EQ(ret, OK); +} + +TEST(rfcStorageTest, setRawValue) { + + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.OsClass"; + const string value = "TestOsClass"; + + bool ret = m_rfcStoreage->setRawValue(key, value); + EXPECT_EQ(ret, true); +} + +TEST(processTest, getNumOfProcessorEntries) { + int instanceNumber = 0; + + hostIf_DeviceProcessorInterface *processorIface = hostIf_DeviceProcessorInterface::getInstance(instanceNumber); + if(processorIface) + { + unsigned int ret = processorIface->getNumOfProcessorEntries(); + EXPECT_EQ(ret, 4); + } +} + +TEST(processTest, get_Device_DeviceInfo_Processor_Architecture) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceProcessorInterface *processorIface = hostIf_DeviceProcessorInterface::getInstance(instanceNumber); + if(processorIface) + { + int ret = processorIface->get_Device_DeviceInfo_Processor_Architecture(&msgData); + cout << "msgData.paramValue = " << msgData.paramValue << endl; + EXPECT_EQ(ret, OK); + EXPECT_STREQ(msgData.paramValue, "x86_64"); + } +} + +TEST(processTest, Processor_Lock_ReleaseLock) { + int instanceNumber = 0; + + hostIf_DeviceProcessorInterface *processorIface = hostIf_DeviceProcessorInterface::getInstance(instanceNumber); + if(processorIface) + { + processorIface->getLock(); + processorIface->releaseLock(); + EXPECT_EQ(0, 0); + } + processorIface->closeInstance(processorIface); + processorIface->closeAllInstances(); + +} + +TEST(processTest, getProcessStatusCPUUsage) { + int instanceNumber = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceProcessStatusInterface *processStatusIface = hostIf_DeviceProcessStatusInterface::getInstance(instanceNumber); + if(processStatusIface) + { + int ret = processStatusIface->getProcessStatusCPUUsage(); + EXPECT_EQ(0, 0); + } +} + + +TEST(processTest, get_Device_DeviceInfo_ProcessStatus_CPUUsage) { + int instanceNumber = 0; + bool pChanged; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceProcessStatusInterface *processStatusIface = hostIf_DeviceProcessStatusInterface::getInstance(instanceNumber); + if(processStatusIface) + { + pChanged = false; + int ret = processStatusIface->get_Device_DeviceInfo_ProcessStatus_CPUUsage(&msgData, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(processTest, getProcessStatParam) { + int instanceNumber = 0; + bool pChanged; + + long long unsigned int mUser = 0; + long long unsigned int mNice = 0; + long long unsigned int mSystem = 0; + long long unsigned int mIdle = 0; + long long unsigned int mIOwait = 0; + long long unsigned int mIrq = 0; + long long unsigned int mSoftirq = 0; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceProcessStatusInterface *processStatusIface = hostIf_DeviceProcessStatusInterface::getInstance(instanceNumber); + if(processStatusIface) + { + pChanged = false; + int ret = processStatusIface->getProcessStatParam(&mUser, &mNice, &mSystem, &mIdle, &mIOwait, &mIrq, &mSoftirq); + EXPECT_EQ(ret, OK); + } +} + +TEST(processTest, ProcessStatus_Lock_ReleaseLock) { + int instanceNumber = 0; + bool pChanged; + + HOSTIF_MsgData_t msgData; + memset(&msgData,0,sizeof(HOSTIF_MsgData_t)); + hostIf_DeviceProcessStatusInterface *processStatusIface = hostIf_DeviceProcessStatusInterface::getInstance(instanceNumber); + if(processStatusIface) + { + pChanged = false; + processStatusIface->getLock(); + processStatusIface->releaseLock(); + EXPECT_EQ(0, 0); + } + processStatusIface->closeInstance(processStatusIface); + processStatusIface->closeAllInstances(); +} + + +TEST(clearTest, rfcclearAll) { + m_rfcStore = XRFCStore::getInstance(); + + m_rfcStore->clearAll(); + EXPECT_EQ(0, 0); +} + +TEST(clearTest, rfcStorageclearAll) { + m_rfcStoreage->clearAll(); + EXPECT_EQ(0, 0); +} + +TEST(StoreClearTest, clearRfcValues) { + m_bsStore = XBSStore::getInstance(); + bool ret = m_bsStore->clearRfcValues(); + EXPECT_EQ(ret, true); +} + +TEST(StoreClearTest, resetCacheAndStore) { + m_bsStore = XBSStore::getInstance(); + m_bsStore->resetCacheAndStore(); + EXPECT_EQ(0, 0); +} + +/* TEST(StoreClearTest, init) { + std::remove("/opt/secure/RFC/tr181store.ini"); + std::ofstream file("/opt/secure/RFC/tr181store.ini"); + file.close(); + + bool ret = m_rfcStoreage->init(); + EXPECT_EQ(ret, false); +} + +TEST(StoreClearTest, getRawValue) { + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.Enable"; + string value = m_rfcStoreage->getRawValue(key); + EXPECT_EQ(value, ""); +} + +TEST(StoreClearTest, setRawValue_Flush) { + m_bsStore = XBSStore::getInstance(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName"; + const string value = "sky"; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + m_bsStore->m_initialUpdate = true; + bool ret = m_bsStore->setRawValue(key, value,param.requestor); + EXPECT_EQ(ret, true); +} */ GTEST_API_ int main(int argc, char *argv[]){ char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE]; diff --git a/src/hostif/profiles/Ethernet/Device_Ethernet_Interface.cpp b/src/hostif/profiles/Ethernet/Device_Ethernet_Interface.cpp index 6184146f7..fb2af1b4d 100644 --- a/src/hostif/profiles/Ethernet/Device_Ethernet_Interface.cpp +++ b/src/hostif/profiles/Ethernet/Device_Ethernet_Interface.cpp @@ -270,7 +270,7 @@ static int get_Device_Ethernet_Interface_Fields(unsigned int ethInterfaceNum,EEt errno_t rc = -1; char cmd[BUFF_LENGTH] = {'\0'}; int temp = 0, isEnabled = 0; - char ethernetInterfaceName[BUFF_LENGTH_64]; + char ethernetInterfaceName[BUFF_LENGTH_64] ={'\0'}; char *value = NULL; if(!ethInterfaceNum) @@ -281,10 +281,10 @@ static int get_Device_Ethernet_Interface_Fields(unsigned int ethInterfaceNum,EEt case eEnable: hostIf_EthernetInterface::stEthInterface.enable = FALSE; - snprintf(cmd,BUFF_LENGTH,"/sys/class/net/%s/carrier", ethernetInterfaceName); - if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName)) + if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName)) return 0; + snprintf(cmd,BUFF_LENGTH,"/sys/class/net/%s/carrier", ethernetInterfaceName); value = readEthernetInterfaceFile(cmd, sizeof(hostIf_EthernetInterface::stEthInterface.enable)); if(value == NULL) return 0; @@ -300,10 +300,10 @@ static int get_Device_Ethernet_Interface_Fields(unsigned int ethInterfaceNum,EEt case eStatus: memset(hostIf_EthernetInterface::stEthInterface.status,'\0',sizeof(hostIf_EthernetInterface::stEthInterface.status)); //CID:45367 - OVERRUN - snprintf(cmd,BUFF_LENGTH,"/sys/class/net/%s/carrier", ethernetInterfaceName); if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName)) return 0; + snprintf(cmd,BUFF_LENGTH,"/sys/class/net/%s/carrier", ethernetInterfaceName); value = readEthernetInterfaceFile(cmd, sizeof(temp)); if(value == NULL) return 0; @@ -344,10 +344,10 @@ static int get_Device_Ethernet_Interface_Fields(unsigned int ethInterfaceNum,EEt case eUpstream: hostIf_EthernetInterface::stEthInterface.upStream = FALSE; - snprintf(cmd,BUFF_LENGTH,"/sys/class/net/%s/carrier", ethernetInterfaceName); - if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName)) + if (OK != getEthernetInterfaceName (ethInterfaceNum, ethernetInterfaceName)) return 0; + snprintf(cmd,BUFF_LENGTH,"/sys/class/net/%s/carrier", ethernetInterfaceName); value = readEthernetInterfaceFile(cmd, sizeof(hostIf_EthernetInterface::stEthInterface.upStream)); if(value == NULL) return 0; @@ -371,7 +371,8 @@ static int get_Device_Ethernet_Interface_Fields(unsigned int ethInterfaceNum,EEt if(value == NULL) return 0; - strncpy(hostIf_EthernetInterface::stEthInterface.mACAddress, value, S_LENGTH); + strncpy(hostIf_EthernetInterface::stEthInterface.mACAddress, value, sizeof(hostIf_EthernetInterface::stEthInterface.mACAddress) - 1); + hostIf_EthernetInterface::stEthInterface.mACAddress[sizeof(hostIf_EthernetInterface::stEthInterface.mACAddress) - 1] = '\0'; RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Interface %u MACAddress: %s \n", __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.mACAddress); @@ -404,7 +405,8 @@ static int get_Device_Ethernet_Interface_Fields(unsigned int ethInterfaceNum,EEt if(value == NULL) return 0; - strncpy(hostIf_EthernetInterface::stEthInterface.duplexMode, value, _BUF_LEN_16); + strncpy(hostIf_EthernetInterface::stEthInterface.duplexMode, value, _BUF_LEN_16- 1); + hostIf_EthernetInterface::stEthInterface.duplexMode[_BUF_LEN_16 - 1] = '\0'; RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s(): Interface %u DuplexMode: %s\n", __FUNCTION__, ethInterfaceNum, hostIf_EthernetInterface::stEthInterface.duplexMode); @@ -892,3 +894,9 @@ int hostIf_EthernetInterface::set_Device_Ethernet_Interface_DuplexMode(HOSTIF_Ms /** @} */ /** @} */ + +#ifdef GTEST_ENABLE +int (*EthernetInterfaceName(void))(unsigned int, char*) { + return &getEthernetInterfaceName; +} +#endif diff --git a/src/hostif/profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp b/src/hostif/profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp index 2cbd2cbc4..bd460ab30 100644 --- a/src/hostif/profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp +++ b/src/hostif/profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp @@ -110,7 +110,7 @@ static int read_Device_Ethernet_Interface_Stats_Fields(unsigned int ethInterface if(ret == -1) { RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in readFile eBytesSent\n"); - + return 0; } break; @@ -121,8 +121,8 @@ static int read_Device_Ethernet_Interface_Stats_Fields(unsigned int ethInterface ret = readStatFile(cmd, hostIf_EthernetInterfaceStats::stEthInterfaceStats.bytesReceived); if(ret == -1) { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in readFile eBytesSent\n"); - + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in readFile eBytesReceived\n"); + return 0; } break; diff --git a/src/hostif/profiles/Ethernet/gtest/Makefile.am b/src/hostif/profiles/Ethernet/gtest/Makefile.am new file mode 100644 index 000000000..1f03470da --- /dev/null +++ b/src/hostif/profiles/Ethernet/gtest/Makefile.am @@ -0,0 +1,40 @@ +################################################################################ +# Copyright 2024 Comcast Cable Communications Management, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +AUTOMAKE_OPTIONS = subdir-objects +# Define the program name and the source files +bin_PROGRAMS = ethernet_gtest + +# Define the include directories +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/handlers/include -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/hostif/profiles/Ethernet -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I/usr/include/rbus -I/usr/local/include/rbus $(GLIB_CFLAGS) $(G_THREAD_CFLAGS) -I/usr/include/libsoup-3.0 + +# Define the libraries to link against +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lsoup-3.0 + +# Define the compiler flags +COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) $(SOUP_LIBS) -fprofile-arcs -ftest-coverage + +# Define the source files +ethernet_gtest_SOURCES = $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/Ethernet/Device_Ethernet_Interface.cpp $(TOP_DIR)/src/hostif/profiles/Ethernet/Device_Ethernet_Interface_Stats.cpp $(TOP_DIR)/src/hostif/profiles/Ethernet/gtest/gtest_ethernet.cpp + + +# Apply common properties to each program +ethernet_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) +ethernet_gtest_LDADD = $(COMMON_LDADD) +ethernet_gtest_CXXFLAGS = $(COMMON_CXXFLAGS) + diff --git a/src/hostif/profiles/Ethernet/gtest/gtest_ethernet.cpp b/src/hostif/profiles/Ethernet/gtest/gtest_ethernet.cpp new file mode 100644 index 000000000..28a6bcb8e --- /dev/null +++ b/src/hostif/profiles/Ethernet/gtest/gtest_ethernet.cpp @@ -0,0 +1,436 @@ +/* + * Copyright 2024 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include + +#include "hostIf_utils.h" +#include "Device_Ethernet_Interface.h" +#include "Device_Ethernet_Interface_Stats.h" +#include "rdk_debug.h" + + +#include +#include "cJSON.h" + +#include +#include + +#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/" +#define GTEST_DEFAULT_RESULT_FILENAME "hostif_gtest_report.json" +#define GTEST_REPORT_FILEPATH_SIZE 128 + +using namespace std; + +#ifdef GTEST_ENABLE +int (*EthernetInterfaceName(void))(unsigned int, char*); +#endif + +TEST(EthernetTest, getEthernetInterfaceName) { + unsigned int ethInterfaceNum = 1; + char name[64]; + int ret = EthernetInterfaceName()(1, name); + EXPECT_EQ(ret, OK); +} + + +TEST(EthernetTest, get_Device_Ethernet_InterfaceNumberOfEntries) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->get_Device_Ethernet_InterfaceNumberOfEntries(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Enable) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->get_Device_Ethernet_Interface_Enable(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Status) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->get_Device_Ethernet_Interface_Status(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Name) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->get_Device_Ethernet_Interface_Name(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Upstream) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->get_Device_Ethernet_Interface_Upstream(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_MACAddress) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->get_Device_Ethernet_Interface_MACAddress(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_MaxBitRate) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->get_Device_Ethernet_Interface_MaxBitRate(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} +TEST(EthernetTest, get_Device_Ethernet_Interface_DuplexMode) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->get_Device_Ethernet_Interface_DuplexMode(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, set_Device_Ethernet_Interface_Enable) { + int instanceNumber = 1; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + strncpy(param.paramValue, "TRUE", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + int ret = ethernetIf->set_Device_Ethernet_Interface_Enable(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, InterfaceLock_ReleaseLock) { + int instanceNumber = 0; + hostIf_EthernetInterface *ethernetIf= hostIf_EthernetInterface::getInstance(instanceNumber); + if(ethernetIf) + { + ethernetIf->getLock(); + ethernetIf->releaseLock(); + EXPECT_EQ(0, 0); + } + ethernetIf->closeInstance(ethernetIf); + ethernetIf->closeAllInstances(); +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_BytesSent) { + int instanceNumber = 1; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_BytesSent(¶m); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_BytesReceived) { + int instanceNumber = 1; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_BytesReceived(¶m); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_PacketsSent) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_PacketsSent(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_PacketsReceived) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_PacketsReceived(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_ErrorsSent) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_ErrorsSent(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_ErrorsReceived) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_ErrorsReceived(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_UnicastPacketsSent) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_UnicastPacketsSent(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_UnicastPacketsReceived) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_UnicastPacketsSent(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_DiscardPacketsSent) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_DiscardPacketsSent(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_DiscardPacketsReceived) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_DiscardPacketsReceived(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_MulticastPacketsSent) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_MulticastPacketsSent(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_MulticastPacketsReceived) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_MulticastPacketsReceived(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_BroadcastPacketsSent) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_BroadcastPacketsSent(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_BroadcastPacketsReceived) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_BroadcastPacketsReceived(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, get_Device_Ethernet_Interface_Stats_UnknownProtoPacketsReceived) { + int instanceNumber = 1; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + int ret = ethernetIfStats->get_Device_Ethernet_Interface_Stats_UnknownProtoPacketsReceived(¶m, &pChanged); + EXPECT_EQ(ret, OK); + } +} + +TEST(EthernetTest, Lock_ReleaseLock) { + int instanceNumber = 0; + hostIf_EthernetInterfaceStats *ethernetIfStats = hostIf_EthernetInterfaceStats::getInstance(instanceNumber); + if(ethernetIfStats) + { + ethernetIfStats->getLock(); + ethernetIfStats->releaseLock(); + EXPECT_EQ(0, 0); + } + ethernetIfStats->closeInstance(ethernetIfStats); + ethernetIfStats->closeAllInstances(); +} + +GTEST_API_ int main(int argc, char *argv[]){ + char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE]; + char buffer[GTEST_REPORT_FILEPATH_SIZE]; + + memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE ); + memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE ); + snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME); + + ::testing::GTEST_FLAG(output) = testresults_fullfilepath; + ::testing::InitGoogleMock(&argc, argv); + std::cout <<"running ut"<< std::endl; + return RUN_ALL_TESTS(); +} diff --git a/src/hostif/profiles/IP/Device_IP_Interface.cpp b/src/hostif/profiles/IP/Device_IP_Interface.cpp index 89d82fc12..a0db01bf5 100755 --- a/src/hostif/profiles/IP/Device_IP_Interface.cpp +++ b/src/hostif/profiles/IP/Device_IP_Interface.cpp @@ -50,8 +50,10 @@ #include #include "Device_IP.h" #include "safec_lib.h" +#ifndef RDKV_TR69 static const char* STATE_UP = "Up"; static const char* STATE_DOWN = "Down"; +#endif // TODO: fix potential bug with initialization, as structure definition now has a "#ifdef IPV6_SUPPORT" IPInterface hostIf_IPInterface::stIPInterfaceInstance = {FALSE,FALSE,FALSE,FALSE,{"Down"},{'\0'},{'\0'},0,{'\0'},{'\0'},FALSE,0,{"Normal"},FALSE,0, diff --git a/src/hostif/profiles/IP/Device_IP_Interface_IPv6Address.cpp b/src/hostif/profiles/IP/Device_IP_Interface_IPv6Address.cpp index 32ab2b3e8..e3ec7214b 100644 --- a/src/hostif/profiles/IP/Device_IP_Interface_IPv6Address.cpp +++ b/src/hostif/profiles/IP/Device_IP_Interface_IPv6Address.cpp @@ -46,10 +46,12 @@ #include "Device_IP.h" #include "safec_lib.h" #include +#ifndef RDKV_TR69 static const char* TIME_INFINITY = "9999-12-31T23:59:59Z"; static const char* TIME_UNKNOWN = "0001-01-01T00:00:00Z"; static const char* STATE_DOWN = "Down"; static const char* NOT_IMPLEMENTED = "Not Implemented"; +#endif /** * @struct in6_ifreq diff --git a/src/hostif/profiles/InterfaceStack/Device_InterfaceStack.cpp b/src/hostif/profiles/InterfaceStack/Device_InterfaceStack.cpp index d747171bc..844c8f43f 100644 --- a/src/hostif/profiles/InterfaceStack/Device_InterfaceStack.cpp +++ b/src/hostif/profiles/InterfaceStack/Device_InterfaceStack.cpp @@ -49,6 +49,7 @@ #define MAX_CMD_LEN 256 #define MAX_IFNAME_LEN 64 #define SYS_CLASS_NET_PATH "/sys/class/net/" +#define MAX_IFCS 256 #define IN #define OUT @@ -728,7 +729,7 @@ int hostif_InterfaceStack::addBridgeChildLayerInfo(InterfaceStackMap_t &layerInf { LayerInfo_t tempLayerInfo; - tempLayerInfo.higherLayer = bridgeHigherLayer; + tempLayerInfo.higherLayer = std::move(bridgeHigherLayer); tempLayerInfo.lowerLayer = std::string(""); layerInfo.insert( std::pair(ifname, tempLayerInfo)); @@ -834,6 +835,38 @@ int hostif_InterfaceStack::buildBridgeTableLayerInfo(InterfaceStackMap_t &layerI return(rc); } +/* getIPInterfaceIDs + * This function populates interface ID Array for all available IP interfaces + */ + +void getIPInterfaceIDs(int *ifindexes) { + int count = 0; + FILE *fp = v_secure_popen("r", "ls /sys/class/net"); + if (!fp) { + perror("popen"); + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s:%d Failed to open /sys/class/net contents\n", __FILE__, __LINE__); + return; + } + + char iface[256]; + while (fgets(iface, sizeof(iface), fp)) { + iface[strcspn(iface, "\n")] = 0; + + //char command[512]; + //snprintf(command, sizeof(command), "cat /sys/class/net/%s/ifindex", iface); + + FILE *ifindex_fp = v_secure_popen("r", "cat /sys/class/net/%s/ifindex", iface); + if (ifindex_fp) { + char buffer[64]; + if (fgets(buffer, sizeof(buffer), ifindex_fp)) { + ifindexes[count++] = atoi(buffer); + } + v_secure_pclose(ifindex_fp); + } + } + v_secure_pclose(fp); +} + /* getIPInterfaces * This function builds up a map for all the available IP interfaces. */ @@ -854,10 +887,13 @@ int hostif_InterfaceStack::getIPInterfaces(IPInterfacesMap_t& interfaceList) ipNumOfEntries=get_int(msgData.paramValue); RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s:%d ipNumOfEntries = %d\n", __FUNCTION__, __LINE__, ipNumOfEntries); - for(ipIndex=1; ipIndex <= ipNumOfEntries; ipIndex++) + int ifindexes[MAX_IFCS]; + getIPInterfaceIDs(ifindexes); + + for(ipIndex=0; ipIndex < ipNumOfEntries && ipIndex < MAX_IFCS; ipIndex++) { std::string ipIfName; - hostIf_IPInterface *pIface = hostIf_IPInterface::getInstance(ipIndex); + hostIf_IPInterface *pIface = hostIf_IPInterface::getInstance(ifindexes[ipIndex]); if(!pIface) { @@ -874,6 +910,9 @@ int hostif_InterfaceStack::getIPInterfaces(IPInterfacesMap_t& interfaceList) interfaceList.insert( std::pair(ipIfName, ipIndex)); } } + if (ipIndex >= MAX_IFCS) { + RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"%s:%d Available interfaces exceeds max no. of interfaces (%d)\n", __FILE__, __LINE__, MAX_IFCS); + } } return(rc); } diff --git a/src/hostif/profiles/STBService/Components_XrdkSDCard.cpp b/src/hostif/profiles/STBService/Components_XrdkSDCard.cpp index 752f11a49..95f54239f 100755 --- a/src/hostif/profiles/STBService/Components_XrdkSDCard.cpp +++ b/src/hostif/profiles/STBService/Components_XrdkSDCard.cpp @@ -504,7 +504,7 @@ int hostIf_STBServiceXSDCard::getSerialNumber(HOSTIF_MsgData_t *stMsgData) memset(¶m, '\0', sizeof(param)); param.eSDPropType = SD_SerialNumber; if(getSDCardProperties(¶m) ) { - sprintf(stMsgData->paramValue,"%s" ,param.sdCardProp.uchVal); + snprintf(stMsgData->paramValue, sizeof(stMsgData->paramValue), "%s", param.sdCardProp.uchVal); } stMsgData->paramtype=hostIf_StringType; } @@ -626,28 +626,37 @@ bool getSDCardProperties(strMgrSDcardPropParam_t *sdCardParam) { if (sdCardParam->eSDPropType == SD_LifeElapsed) { - eSTMGRHealthInfo healthInfo; - memset (&healthInfo, 0 , sizeof(healthInfo)); - if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getHealth (sdCardDeviceID, &healthInfo)) + eSTMGRHealthInfo* healthInfo = (eSTMGRHealthInfo*)malloc(sizeof(eSTMGRHealthInfo)); + if (healthInfo != NULL) { - sdCardParam->sdCardProp.iVal = -1; - /* FIXME: Update string from "used" to a proper proposed value */ - for (int i = 0; i < healthInfo.m_diagnostics.m_list.m_numOfAttributes; i++) + memset(healthInfo, 0, sizeof(eSTMGRHealthInfo)); + if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getHealth(sdCardDeviceID, healthInfo)) { - if (0 == strcmp (healthInfo.m_diagnostics.m_list.m_diagnostics[i].m_name, "used")) + sdCardParam->sdCardProp.iVal = -1; + /* FIXME: Update string from "used" to a proper proposed value */ + for (int i = 0; i < healthInfo->m_diagnostics.m_list.m_numOfAttributes; i++) { - sdCardParam->sdCardProp.iVal = atoi (healthInfo.m_diagnostics.m_list.m_diagnostics[i].m_value); - break; + if (0 == strcmp(healthInfo->m_diagnostics.m_list.m_diagnostics[i].m_name, "used")) + { + sdCardParam->sdCardProp.iVal = atoi(healthInfo->m_diagnostics.m_list.m_diagnostics[i].m_value); + break; + } } } + else + { + sdCardParam->sdCardProp.iVal = -1; + } + free(healthInfo); } else - { + { + // Handle memory allocation failure sdCardParam->sdCardProp.iVal = -1; } - } - else - { + } + else + { eSTMGRDeviceInfo deviceInfo; memset (&deviceInfo, 0 , sizeof(deviceInfo)); if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (sdCardDeviceID, &deviceInfo)) diff --git a/src/hostif/profiles/Time/Device_Time.cpp b/src/hostif/profiles/Time/Device_Time.cpp index 1c2f8de3d..0ecddf911 100644 --- a/src/hostif/profiles/Time/Device_Time.cpp +++ b/src/hostif/profiles/Time/Device_Time.cpp @@ -168,6 +168,7 @@ int hostIf_Time::get_Device_Time_LocalTimeZone(HOSTIF_MsgData_t *stMsgData, bool { struct timeval time_now; struct tm *newtime = NULL; + char tmp[_BUF_LEN_64]; @@ -186,9 +187,10 @@ int hostIf_Time::get_Device_Time_LocalTimeZone(HOSTIF_MsgData_t *stMsgData, bool } bCalledLocalTimeZone = true; - strncpy(stMsgData->paramValue,tmp,_BUF_LEN_64-1); - strncpy(backupLocalTimeZone,tmp,_BUF_LEN_64-1); - + strncpy(stMsgData->paramValue,tmp,sizeof(stMsgData->paramValue) -1); + stMsgData->paramValue[sizeof(stMsgData->paramValue) - 1] = '\0'; + strncpy(backupLocalTimeZone,tmp,sizeof(backupLocalTimeZone) -1); + backupLocalTimeZone[sizeof(backupLocalTimeZone) -1] = '\0'; stMsgData->paramtype = hostIf_StringType; stMsgData->paramLen = strlen(stMsgData->paramValue); return OK; @@ -226,7 +228,7 @@ int hostIf_Time::get_Device_Time_CurrentLocalTime(HOSTIF_MsgData_t *stMsgData, b { time_t rawtime; struct tm * timeinfo; - errno_t rc = -1; + errno_t rc = -1; char buffer [_BUF_LEN_64] = {'\0'}; RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FILE__, __FUNCTION__); char timeZoneTmp[7]; diff --git a/src/hostif/profiles/Time/Device_Time.h b/src/hostif/profiles/Time/Device_Time.h index 9378b49bf..7fc5cd481 100644 --- a/src/hostif/profiles/Time/Device_Time.h +++ b/src/hostif/profiles/Time/Device_Time.h @@ -436,6 +436,10 @@ class hostIf_Time { int get_Device_Time_CurrentUTCTime(HOSTIF_MsgData_t *, bool *pChanged = NULL); +#if defined(GTEST_ENABLE) + FRIEND_TEST(TimeTest, releaseLock); +#endif + }; /* End of TR_069_DEVICE_TIME_SETTER_API doxygen group. */ /** diff --git a/src/hostif/profiles/Time/gtest/Makefile.am b/src/hostif/profiles/Time/gtest/Makefile.am new file mode 100644 index 000000000..b3b56f490 --- /dev/null +++ b/src/hostif/profiles/Time/gtest/Makefile.am @@ -0,0 +1,38 @@ +################################################################################ +# Copyright 2024 Comcast Cable Communications Management, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +AUTOMAKE_OPTIONS = subdir-objects +# Define the program name and the source files +bin_PROGRAMS = time_gtest + +# Define the include directories +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -DPARODUS -DUNIT_TEST -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/handlers/include -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/hostif/profiles/Time -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I/usr/include/rbus -I/usr/local/include/rbus $(GLIB_CFLAGS) $(G_THREAD_CFLAGS) -I/usr/include/libsoup-3.0 + +# Define the libraries to link against +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lsoup-3.0 + +# Define the compiler flags +COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) $(SOUP_LIBS) -fprofile-arcs -ftest-coverage + +# Define the source files +time_gtest_SOURCES = $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_NotificationHandler.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_notification.cpp $(TOP_DIR)/src/hostif/profiles/Time/Device_Time.cpp $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/hostif/profiles/Time/gtest/gtest_time.cpp + +# Apply common properties to each program +time_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) +time_gtest_LDADD = $(COMMON_LDADD) +time_gtest_CXXFLAGS = $(COMMON_CXXFLAGS) diff --git a/src/hostif/profiles/Time/gtest/gtest_time.cpp b/src/hostif/profiles/Time/gtest/gtest_time.cpp new file mode 100644 index 000000000..6d07b29e5 --- /dev/null +++ b/src/hostif/profiles/Time/gtest/gtest_time.cpp @@ -0,0 +1,168 @@ +/* + * Copyright 2024 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include "hostIf_utils.h" +#include "Device_Time.h" +#include "rdk_debug.h" + + +#include +#include "cJSON.h" + +#include +#include + +#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/" +#define GTEST_DEFAULT_RESULT_FILENAME "hostif_gtest_report.json" +#define GTEST_REPORT_FILEPATH_SIZE 128 + +using namespace std; + +TEST(TimeTest, get_Device_Time_LocalTimeZone) { + int instanceNumber = 0; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_Time *hostIfTime= hostIf_Time::getInstance(instanceNumber); + if(hostIfTime) + { + int ret = hostIfTime->get_Device_Time_LocalTimeZone(¶m); + EXPECT_EQ(ret, OK); + EXPECT_EQ(param.paramtype, hostIf_StringType); + } +} + +TEST(TimeTest, get_Device_Time_CurrentLocalTime) { + int instanceNumber = 0; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_Time *hostIfTime= hostIf_Time::getInstance(instanceNumber); + if(hostIfTime) + { + int ret = hostIfTime->get_Device_Time_CurrentLocalTime(¶m, &pChanged); + EXPECT_EQ(ret, OK); + EXPECT_EQ(param.paramtype, hostIf_StringType); + } +} + +TEST(TimeTest, get_xRDKCentralComBootstrap) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.XDial.AppList", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_StringType; + param.paramLen = sizeof(hostIf_StringType); + + hostIf_Time *hostIfTime= hostIf_Time::getInstance(instanceNumber); + if(hostIfTime) + { + int ret = hostIfTime->get_xRDKCentralComBootstrap(¶m); + std::string value = getStringValue(¶m); + EXPECT_EQ(ret, OK); + EXPECT_EQ(value, "youtube:spotify:netflix:system"); + } +} + +TEST(TimeTest, set_xRDKCentralComBootstrap) { + int instanceNumber = 0; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_SET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfUrl", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + strncpy(param.paramValue, "https://xconf.xdp.eu-1.xcal.tv", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + hostIf_Time *hostIfTime= hostIf_Time::getInstance(instanceNumber); + if(hostIfTime) + { + int ret = hostIfTime->set_xRDKCentralComBootstrap(¶m); + EXPECT_EQ(ret, OK); + } +} + +TEST(TimeTest, get_Device_Time_CurrentUTCTime) { + int instanceNumber = 0; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_Time *hostIfTime= hostIf_Time::getInstance(instanceNumber); + if(hostIfTime) + { + int ret = hostIfTime->get_Device_Time_CurrentUTCTime(¶m, &pChanged); + EXPECT_EQ(ret, OK); + EXPECT_EQ(param.paramtype, hostIf_StringType); + } +} + +TEST(TimeTest, releaseLock) { + int instanceNumber = 0; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_Time *hostIfTime= hostIf_Time::getInstance(instanceNumber); + if(hostIfTime) + { + hostIfTime->getLock(); + gboolean locked = g_mutex_trylock(&hostIfTime->m_mutex); + EXPECT_EQ(locked, false); + hostIfTime->releaseLock(); + } +} + +TEST(TimeTest, closeInstance) { + int instanceNumber = 0; + bool pChanged = false; + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + + hostIf_Time *hostIfTime= hostIf_Time::getInstance(instanceNumber); + if(hostIfTime) + { + hostIf_Time::closeInstance(hostIfTime); + hostIfTime->closeAllInstances(); + } +} + +GTEST_API_ int main(int argc, char *argv[]){ + char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE]; + char buffer[GTEST_REPORT_FILEPATH_SIZE]; + + memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE ); + memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE ); + snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME); + + ::testing::GTEST_FLAG(output) = testresults_fullfilepath; + ::testing::InitGoogleMock(&argc, argv); + std::cout <<"running ut"<< std::endl; + return RUN_ALL_TESTS(); +} diff --git a/src/hostif/profiles/wifi/Device_WiFi.cpp b/src/hostif/profiles/wifi/Device_WiFi.cpp index c019bff25..a1fd34d18 100644 --- a/src/hostif/profiles/wifi/Device_WiFi.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi.cpp @@ -43,9 +43,18 @@ #include "Device_WiFi.h" #include #include +#ifdef RDKV_NM +extern "C" { + /* #include "c_only_header.h"*/ +#include "wifi_client_hal.h" +#include "wifiSrvMgrIarmIf.h" +#include "netsrvmgrIarm.h" +}; +#else #include #include "cJSON.h" #include "hostIf_utils.h" +#endif //char *moca_interface = NULL; GHashTable* WiFiDevice::devHash = NULL; @@ -226,7 +235,64 @@ void hostIf_WiFi::closeAllInstances() /****************************************************************************************************************************************************/ // Device.WiFi. Profile. Getters: /****************************************************************************************************************************************************/ +#ifdef RDKV_NM +int hostIf_WiFi::get_Device_WiFi_RadioNumberOfEntries(HOSTIF_MsgData_t *stMsgData) +{ + ULONG radioNumOfEntries = 0; + IARM_Result_t retVal = IARM_RESULT_SUCCESS; + IARM_BUS_WiFi_DiagsPropParam_t param; + int ret = OK; + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + + param.numEntry=IARM_BUS_WIFI_MGR_RadioEntry; +// ret = wifi_getRadioNumberOfEntries(&radioNumOfEntries); + + retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getSSIDProps, (void *)¶m, sizeof(param)); + if (IARM_RESULT_SUCCESS != retVal) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal); + return NOK; + } + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] param.data.radioNumberOfEntries returned %d radioNumOfEntries:%lu\n", + __FUNCTION__, __FILE__, ret, param.data.radioNumberOfEntries); + radioNumOfEntries=param.data.radioNumberOfEntries; + put_int(stMsgData->paramValue,radioNumOfEntries); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen = sizeof(radioNumOfEntries); + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + + return ret; +} + +int hostIf_WiFi::get_Device_WiFi_SSIDNumberOfEntries(HOSTIF_MsgData_t *stMsgData) +{ + ULONG ssidNumOfEntries = 0; + IARM_Result_t retVal = IARM_RESULT_SUCCESS; + int ret = OK; + IARM_BUS_WiFi_DiagsPropParam_t param; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + param.numEntry=IARM_BUS_WIFI_MGR_SSIDEntry; + + retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getSSIDProps, (void *)¶m, sizeof(param)); + if (IARM_RESULT_SUCCESS != retVal) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal); + return NOK; + } + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering.. param.data.ssidNumberOfEntries %d \n", __FUNCTION__, __FILE__,param.data.ssidNumberOfEntries); + ssidNumOfEntries=param.data.ssidNumberOfEntries; + put_int(stMsgData->paramValue,ssidNumOfEntries); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen = 4; + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + + return ret; +} +#endif int hostIf_WiFi::get_Device_WiFi_AccessPointNumberOfEntries(HOSTIF_MsgData_t *stMsgData) { unsigned int accessPointNumOfEntries = 1; @@ -253,13 +319,26 @@ int hostIf_WiFi::get_Device_WiFi_EndPointNumberOfEntries(HOSTIF_MsgData_t *stMsg return OK; } +#ifdef RDKV_NM +int hostIf_WiFi::get_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData) +{ + LOG_ENTRY_EXIT; + IARM_BUS_NetSrvMgr_Iface_EventData_t param = {0}; + snprintf (param.setInterface, INTERFACE_SIZE, "WIFI"); + IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_isInterfaceEnabled, (void*)¶m, sizeof(param)); + put_boolean(stMsgData->paramValue, param.isInterfaceEnabled); + stMsgData->paramtype = hostIf_BooleanType; + stMsgData->paramLen=1; + return OK; +} +#else int hostIf_WiFi::get_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData) { LOG_ENTRY_EXIT; std::string postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetAvailableInterfaces\"}"; - string response = getJsonRPCData(postData); + string response = getJsonRPCData(std::move(postData)); if(response.c_str()) { @@ -281,7 +360,7 @@ int hostIf_WiFi::get_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData) } //ASSIGN TO OP HERE - cJSON *result = cJSON_GetObjectItem(interface, "isEnabled"); + cJSON *result = cJSON_GetObjectItem(interface, "enabled"); put_boolean(stMsgData->paramValue, result->type); stMsgData->paramtype = hostIf_BooleanType; stMsgData->paramLen=1; @@ -307,7 +386,43 @@ int hostIf_WiFi::get_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData) } return OK; } +#endif +#ifdef RDKV_NM +int hostIf_WiFi::set_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData) +{ + LOG_ENTRY_EXIT; + if (stMsgData->paramtype != hostIf_BooleanType) + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Failed due to wrong data type for %s, please use boolean(0/1) to set.\n", __FUNCTION__, stMsgData->paramName); + stMsgData->faultCode = fcInvalidParameterType; + return NOK; + } + IARM_BUS_NetSrvMgr_Iface_EventData_t iarmData = { 0 }; + snprintf (iarmData.setInterface, INTERFACE_SIZE, "WIFI"); + iarmData.isInterfaceEnabled = get_boolean(stMsgData->paramValue); + iarmData.persist = true; // set interface control persistence = true, whether WiFi is asked to be enabled or not + + if (IARM_RESULT_SUCCESS == IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME, + IARM_BUS_NETSRVMGR_API_setInterfaceEnabled, + (void*)&iarmData, sizeof(iarmData))) + { + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, + "[%s] IARM call succeeded %s %s (interface = %s enabled = %d persist = %d)\n", + __FUNCTION__, IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_setInterfaceEnabled, + iarmData.setInterface, iarmData.isInterfaceEnabled, iarmData.persist); + return OK; + } + else + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, + "[%s] IARM call failed %s %s (interface = %s enabled = %d persist = %d)\n", + __FUNCTION__, IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_setInterfaceEnabled, + iarmData.setInterface, iarmData.isInterfaceEnabled, iarmData.persist); + return NOK; + } +} +#else int hostIf_WiFi::set_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData) { LOG_ENTRY_EXIT; @@ -327,7 +442,7 @@ int hostIf_WiFi::set_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData) postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.DisableInterface\", \"params\" : { \"type\" : \"WIFI\"}}"; } - string response = getJsonRPCData(postData); + string response = getJsonRPCData(std::move(postData)); if(response.c_str()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); @@ -362,6 +477,7 @@ int hostIf_WiFi::set_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData) } return OK; } +#endif #endif /* End of doxygen group */ diff --git a/src/hostif/profiles/wifi/Device_WiFi.h b/src/hostif/profiles/wifi/Device_WiFi.h index 6147f5dfc..3056df8aa 100644 --- a/src/hostif/profiles/wifi/Device_WiFi.h +++ b/src/hostif/profiles/wifi/Device_WiFi.h @@ -207,6 +207,22 @@ class hostIf_WiFi { static GList* getAllIntefaces(); static void closeAllInstances(); + #ifdef RDKV_NM + /** + * @ingroup TR69_HOSTIF_WIFI_API + * @{ + */ + /** + * @brief This function provides the number of entries in the Radio table. + */ + int get_Device_WiFi_RadioNumberOfEntries(HOSTIF_MsgData_t *); + + + /** + * @brief This function provides the number of entries in the SSID table. + */ + int get_Device_WiFi_SSIDNumberOfEntries(HOSTIF_MsgData_t *); + #endif /** * @brief This function provides the number of entries in the AccessPoint table. */ diff --git a/src/hostif/profiles/wifi/Device_WiFi_EndPoint.cpp b/src/hostif/profiles/wifi/Device_WiFi_EndPoint.cpp index 220f30838..72dfd8c58 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_EndPoint.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi_EndPoint.cpp @@ -39,9 +39,15 @@ #include "Device_WiFi_EndPoint.h" #include #include "safec_lib.h" +#ifdef RDKV_NM +extern "C" { +#include "wifiSrvMgrIarmIf.h" +}; +#else #include #include "cJSON.h" #include "hostIf_utils.h" +#endif GHashTable* hostIf_WiFi_EndPoint::ifHash = NULL; @@ -268,6 +274,55 @@ int hostIf_WiFi_EndPoint::get_Device_WiFi_EndPoint_Stats_Retransmissions (HOSTIF /** * @brief Refreshes the cache of Device.WiFi.EndPoint. parameters */ +#ifdef RDKV_NM +int hostIf_WiFi_EndPoint::refreshCache() +{ + LOG_ENTRY_EXIT; + static time_t time_of_last_successful_query = 0; + static int last_call_status = NOK; + static std::mutex m; + std::lock_guard lg (m); + // Using a 1-second cache. + if ((last_call_status == OK ) && (time (0) <= time_of_last_successful_query + 1)) + { + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s] Cache not stale. last call status is SUCCESS, Refresh not required.\n", __FUNCTION__); + return OK; + } + + IARM_BUS_WiFi_DiagsPropParam_t param; + IARM_Result_t retVal = IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getEndPointProps, (void *) ¶m, sizeof(param)); + if (IARM_RESULT_SUCCESS != retVal) + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Cache refresh failed. IARM_Bus_Call to netsrvmgr returned [%d]\n", __FUNCTION__, retVal); + last_call_status = NOK; + return NOK; + } + + time_of_last_successful_query = time (0); + + Enable = param.data.endPointInfo.enable; + strncpy (Status, param.data.endPointInfo.status, BUFF_LENGTH_64); + strncpy (Alias, param.data.endPointInfo.alias, BUFF_LENGTH_64); + strncpy (ProfileReference, param.data.endPointInfo.ProfileReference, BUFF_LENGTH_256); + strncpy (SSIDReference, param.data.endPointInfo.SSIDReference, BUFF_LENGTH_256); + ProfileNumberOfEntries = param.data.endPointInfo.ProfileNumberOfEntries; + stats.LastDataDownlinkRate = param.data.endPointInfo.stats.lastDataDownlinkRate; + stats.LastDataUplinkRate = param.data.endPointInfo.stats.lastDataUplinkRate; + stats.SignalStrength = param.data.endPointInfo.stats.signalStrength; + stats.Retransmissions = param.data.endPointInfo.stats.retransmissions; + + RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s] Cache refreshed.\n", __FUNCTION__); + + if (false == param.data.endPointInfo.enable) // "Disabled" endpoint + { + RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] EndPoint is disabled\n", __FUNCTION__); + last_call_status = NOK; + return OK; + } + last_call_status = OK; + return OK; +} +#else int hostIf_WiFi_EndPoint::refreshCache() { LOG_ENTRY_EXIT; @@ -288,7 +343,7 @@ int hostIf_WiFi_EndPoint::refreshCache() std::string postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetWifiState\"}"; - string response = getJsonRPCData(postData); + string response = getJsonRPCData(std::move(postData)); if(response.c_str()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); @@ -309,7 +364,7 @@ int hostIf_WiFi_EndPoint::refreshCache() } //ASSIGN TO OP HERE - cJSON *result = cJSON_GetObjectItem(interface, "isEnabled"); + cJSON *result = cJSON_GetObjectItem(interface, "enabled"); Enable = result->type; cJSON *state = cJSON_GetObjectItem(jsonObj, "state"); @@ -395,6 +450,7 @@ int hostIf_WiFi_EndPoint::refreshCache() cJSON *ssid = cJSON_GetObjectItem(jsonObj, "ssid"); //ASSIGN TO OP HERE strncpy (SSIDReference, ssid->valuestring, BUFF_LENGTH_256); + SSIDReference[BUFF_LENGTH_256 - 1] = '\0'; } else { @@ -417,7 +473,7 @@ int hostIf_WiFi_EndPoint::refreshCache() } postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetWiFiSignalStrength\"}"; - response = getJsonRPCData(postData); + response = getJsonRPCData(std::move(postData)); if(response.c_str()) { @@ -470,5 +526,5 @@ int hostIf_WiFi_EndPoint::refreshCache() last_call_status = OK; return OK; } - +#endif #endif /* #ifdef USE_WIFI_PROFILE */ diff --git a/src/hostif/profiles/wifi/Device_WiFi_EndPoint_Security.cpp b/src/hostif/profiles/wifi/Device_WiFi_EndPoint_Security.cpp index bec0970c9..5630d7e64 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_EndPoint_Security.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi_EndPoint_Security.cpp @@ -37,10 +37,15 @@ *****************************************************************************/ #ifdef USE_WIFI_PROFILE #include "Device_WiFi_EndPoint_Security.h" +#ifdef RDKV_NM +extern "C" { +#include "wifiSrvMgrIarmIf.h" +}; +#else #include #include "cJSON.h" #include "hostIf_utils.h" - +#endif GHashTable* hostIf_WiFi_EndPoint_Security::ifHash = NULL; hostIf_WiFi_EndPoint_Security* hostIf_WiFi_EndPoint_Security::getInstance(int dev_id) @@ -111,7 +116,37 @@ hostIf_WiFi_EndPoint_Security::hostIf_WiFi_EndPoint_Security(int dev_id) { memset(ModesSupported, 0, 64); } +#ifdef RDKV_NM +int hostIf_WiFi_EndPoint_Security::get_hostIf_WiFi_EndPoint_Security_ModesEnabled(HOSTIF_MsgData_t *stMsgData ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering.. \n", __FUNCTION__, __FILE__); + + IARM_Result_t retVal = IARM_RESULT_IPCCORE_FAIL; + IARM_Bus_WiFiSrvMgr_Param_t param; + if(NULL == stMsgData) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Input arg stMsgData is NULL\n", __FILE__, __FUNCTION__); + return retVal; + } + + memset(¶m, 0, sizeof(param)); + retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getPairedSSIDInfo, (void *)¶m, sizeof(param)); + + if(retVal != IARM_RESULT_SUCCESS) { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal); + return retVal; + }else{ + strncpy(stMsgData->paramValue,param.data.getPairedSSIDInfo.security,sizeof(stMsgData->paramValue)); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(stMsgData->paramValue); + retVal = IARM_RESULT_SUCCESS; + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s] WiFi Security Mode : %s\n",__FUNCTION__,stMsgData->paramValue); + } + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return retVal; +} +#else int hostIf_WiFi_EndPoint_Security::get_hostIf_WiFi_EndPoint_Security_ModesEnabled(HOSTIF_MsgData_t *stMsgData ) { RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering.. \n", __FUNCTION__, __FILE__); @@ -126,7 +161,7 @@ int hostIf_WiFi_EndPoint_Security::get_hostIf_WiFi_EndPoint_Security_ModesEnable std::string postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetConnectedSSID\"}"; - string response = getJsonRPCData(postData); + string response = getJsonRPCData(std::move(postData)); if(response.c_str()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); @@ -140,7 +175,8 @@ int hostIf_WiFi_EndPoint_Security::get_hostIf_WiFi_EndPoint_Security_ModesEnable cJSON *securityModeObj = cJSON_GetObjectItem(jsonObj, "securityMode"); //ASSIGN TO OP HERE - strncpy(stMsgData->paramValue,securityModeObj->valuestring,sizeof(stMsgData->paramValue)); + strncpy(stMsgData->paramValue,securityModeObj->valuestring,sizeof(stMsgData->paramValue) -1); + stMsgData->paramValue[sizeof(stMsgData->paramValue) - 1] = '\0'; stMsgData->paramtype = hostIf_StringType; stMsgData->paramLen = strlen(stMsgData->paramValue); @@ -171,6 +207,7 @@ int hostIf_WiFi_EndPoint_Security::get_hostIf_WiFi_EndPoint_Security_ModesEnable RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); return retVal; } +#endif int hostIf_WiFi_EndPoint_Security::get_hostIf_WiFi_EndPoint_ModesSupported(HOSTIF_MsgData_t *stMsgData ) { return 0; diff --git a/src/hostif/profiles/wifi/Device_WiFi_Radio.cpp b/src/hostif/profiles/wifi/Device_WiFi_Radio.cpp index f6cde044f..affca9375 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_Radio.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi_Radio.cpp @@ -39,6 +39,14 @@ *****************************************************************************/ #include "Device_WiFi_Radio.h" +#ifdef RDKV_NM +extern "C" { + /* #include "c_only_header.h"*/ +#include "wifi_client_hal.h" +#include "wifiSrvMgrIarmIf.h" +}; +#endif + GHashTable* hostIf_WiFi_Radio::ifHash = NULL; /*hostIf_WiFi_Radio::hostIf_WiFi_Radio(int dev_id):dev_id(dev_id) @@ -147,5 +155,381 @@ hostIf_WiFi_Radio::hostIf_WiFi_Radio(int dev_id): memset(TransmitPowerSupported, 0, sizeof(TransmitPowerSupported)); memset(RegulatoryDomain, 0, sizeof(RegulatoryDomain)); } +#ifdef RDKV_NM +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Props_Fields(int radioIndex) +{ + IARM_Result_t retVal = IARM_RESULT_SUCCESS; + IARM_BUS_WiFi_DiagsPropParam_t param = {0}; + int ret; + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + hostIf_WiFi_Radio *pDev = hostIf_WiFi_Radio::getInstance(dev_id); + if(pDev) + { + retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getRadioProps, (void *)¶m, sizeof(param)); + if (IARM_RESULT_SUCCESS != retVal) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal); + return NOK; + } + Enable = param.data.radio.params.enable; + snprintf(Status,BUFF_LENGTH_64,param.data.radio.params.status); + snprintf(Alias,BUFF_LENGTH_64,param.data.radio.params.alias); + snprintf(Name,BUFF_LENGTH_64,param.data.radio.params.name); + LastChange = param.data.radio.params.lastChange; + snprintf(LowerLayers,BUFF_LENGTH_1024,param.data.radio.params.lowerLayers); + Upstream = param.data.radio.params.upstream; + MaxBitRate = param.data.radio.params.maxBitRate; + snprintf(SupportedFrequencyBands,BUFF_LENGTH_256,param.data.radio.params.supportedFrequencyBands); + snprintf(OperatingFrequencyBand,BUFF_LENGTH_64,param.data.radio.params.operatingFrequencyBand); + snprintf(SupportedStandards,BUFF_LENGTH_64,param.data.radio.params.supportedStandards); + snprintf(OperatingStandards,BUFF_LENGTH_64,param.data.radio.params.operatingStandards); + snprintf(PossibleChannels,BUFF_LENGTH_256,param.data.radio.params.possibleChannels); + snprintf(ChannelsInUse,BUFF_LENGTH_1024,param.data.radio.params.channelsInUse); + Channel = param.data.radio.params.channel; + AutoChannelSupported = param.data.radio.params.autoChannelSupported; + AutoChannelEnable = param.data.radio.params.autoChannelEnable; + AutoChannelRefreshPeriod = param.data.radio.params.autoChannelRefreshPeriod; + snprintf(OperatingChannelBandwidth,BUFF_LENGTH_1024,param.data.radio.params.operatingChannelBandwidth); + snprintf(ExtensionChannel,BUFF_LENGTH_64,param.data.radio.params.extensionChannel); + snprintf(GuardInterval,BUFF_LENGTH_64,param.data.radio.params.guardInterval); + mcs = param.data.radio.params.mcs; + snprintf(TransmitPowerSupported,BUFF_LENGTH_64,param.data.radio.params.transmitPowerSupported); + TransmitPower = param.data.radio.params.transmitPower; +// IEEE80211hSupported = param.data.radio.params.IEEE80211hSupported; +// IEEE80211hEnabled = param.data.radio.params.IEEE80211hEnabled; + snprintf(RegulatoryDomain,BUFF_MIN_16,param.data.radio.params.regulatoryDomain); + radioFirstExTime = time (NULL); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__); + return NOK; + } +} + +void hostIf_WiFi_Radio::checkWifiRadioFetch(int radioIndex) +{ + int retVal=NOK; + time_t currExTime = time (NULL); + if((currExTime - radioFirstExTime ) > QUERY_INTERVAL) + { + retVal = get_Device_WiFi_Radio_Props_Fields(radioIndex); + if( OK != retVal) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Failed to fetch : %d.\n", __FILE__, __FUNCTION__, retVal); + } + } +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Enable(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_boolean(stMsgData->paramValue, Enable); + stMsgData->paramtype = hostIf_BooleanType; + stMsgData->paramLen=1; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Upstream(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_boolean(stMsgData->paramValue, Upstream); + stMsgData->paramtype = hostIf_BooleanType; + stMsgData->paramLen=1; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_AutoChannelSupported(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_boolean(stMsgData->paramValue, AutoChannelSupported); + stMsgData->paramtype = hostIf_BooleanType; + stMsgData->paramLen=1; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_AutoChannelEnable(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_boolean(stMsgData->paramValue, AutoChannelEnable); + stMsgData->paramtype = hostIf_BooleanType; + stMsgData->paramLen=1; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_IEEE80211hSupported(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_boolean(stMsgData->paramValue, IEEE80211hSupported); + stMsgData->paramtype = hostIf_BooleanType; + stMsgData->paramLen=1; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_IEEE80211hEnabled(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + + + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_boolean(stMsgData->paramValue, IEEE80211hEnabled); + stMsgData->paramtype = hostIf_BooleanType; + stMsgData->paramLen=1; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_LastChange(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_int(stMsgData->paramValue, LastChange); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_MaxBitRate(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_int(stMsgData->paramValue, MaxBitRate); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Channel(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_int(stMsgData->paramValue, Channel); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_AutoChannelRefreshPeriod(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_int(stMsgData->paramValue, AutoChannelRefreshPeriod); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_MCS(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_int(stMsgData->paramValue, mcs); + stMsgData->paramtype = hostIf_IntegerType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_TransmitPower(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + put_int(stMsgData->paramValue, TransmitPower); + stMsgData->paramtype = hostIf_IntegerType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Status(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, Status,TR69HOSTIFMGR_MAX_PARAM_LEN); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(Status); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Alias(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, Alias,TR69HOSTIFMGR_MAX_PARAM_LEN); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(Alias); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_Name(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, Name,TR69HOSTIFMGR_MAX_PARAM_LEN); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(Name); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_SupportedFrequencyBands(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, SupportedFrequencyBands,TR69HOSTIFMGR_MAX_PARAM_LEN); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(SupportedFrequencyBands); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_OperatingFrequencyBand(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, OperatingFrequencyBand,TR69HOSTIFMGR_MAX_PARAM_LEN ); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(OperatingFrequencyBand); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_SupportedStandards(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, SupportedStandards,TR69HOSTIFMGR_MAX_PARAM_LEN ); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(SupportedStandards); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_OperatingStandards(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, OperatingStandards,TR69HOSTIFMGR_MAX_PARAM_LEN ); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(OperatingStandards); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_PossibleChannels(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, PossibleChannels,TR69HOSTIFMGR_MAX_PARAM_LEN); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(PossibleChannels); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_ChannelsInUse(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, ChannelsInUse,TR69HOSTIFMGR_MAX_PARAM_LEN ); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(ChannelsInUse); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_OperatingChannelBandwidth(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, OperatingChannelBandwidth,TR69HOSTIFMGR_MAX_PARAM_LEN); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(OperatingChannelBandwidth); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_ExtensionChannel(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, ExtensionChannel,TR69HOSTIFMGR_MAX_PARAM_LEN ); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(ExtensionChannel); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_GuardInterval(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, GuardInterval,TR69HOSTIFMGR_MAX_PARAM_LEN ); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(GuardInterval); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_LowerLayers(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, LowerLayers,TR69HOSTIFMGR_MAX_PARAM_LEN ); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(LowerLayers); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_TransmitPowerSupported(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, TransmitPowerSupported,TR69HOSTIFMGR_MAX_PARAM_LEN ); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(TransmitPowerSupported); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio::get_Device_WiFi_Radio_RegulatoryDomain(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioFetch(radioIndex); + strncpy(stMsgData->paramValue, RegulatoryDomain,TR69HOSTIFMGR_MAX_PARAM_LEN); + stMsgData->paramtype = hostIf_StringType; + stMsgData->paramLen = strlen(RegulatoryDomain); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} +#endif #endif /* #ifdef USE_WIFI_PROFILE */ diff --git a/src/hostif/profiles/wifi/Device_WiFi_Radio.h b/src/hostif/profiles/wifi/Device_WiFi_Radio.h index 045fe3f3a..348bb690b 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_Radio.h +++ b/src/hostif/profiles/wifi/Device_WiFi_Radio.h @@ -118,7 +118,10 @@ class hostIf_WiFi_Radio { static GList* getAllAssociateDevs(); static void closeInstance(hostIf_WiFi_Radio *); static void closeAllInstances(); - + #ifdef RDKV_NM + int get_Device_WiFi_Radio_Props_Fields(int radioIndex); + void checkWifiRadioFetch(int radioIndex); + #endif bool Enable; char Status[BUFF_LENGTH_64]; char Alias[BUFF_LENGTH_64]; diff --git a/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.cpp b/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.cpp index ce37ab4fc..5fa032b7f 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.cpp @@ -36,9 +36,17 @@ * STANDARD INCLUDE FILES *****************************************************************************/ #include "Device_WiFi_Radio_Stats.h" - +#ifdef RDKV_NM +extern "C" { +#include "wifiSrvMgrIarmIf.h" + /* #include "c_only_header.h"*/ +}; +#endif GHashTable* hostIf_WiFi_Radio_Stats::ifHash = NULL; +#ifdef RDKV_NM +static time_t radioFirstExTime = 0; +#endif hostIf_WiFi_Radio_Stats *hostIf_WiFi_Radio_Stats::getInstance(int dev_id) { @@ -111,4 +119,156 @@ hostIf_WiFi_Radio_Stats::hostIf_WiFi_Radio_Stats(int dev_id): } +#ifdef RDKV_NM +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_Props_Fields(int radioIndex) +{ + IARM_Result_t retVal = IARM_RESULT_SUCCESS; + IARM_BUS_WiFi_DiagsPropParam_t param = {0}; + int ret; + radioIndex=1; + + hostIf_WiFi_Radio_Stats *pDev = hostIf_WiFi_Radio_Stats::getInstance(dev_id); + if(pDev) + { + retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getRadioStatsProps, (void *)¶m, sizeof(param)); + if (IARM_RESULT_SUCCESS != retVal) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal); + return NOK; + } + BytesSent = param.data.radio_stats.params.bytesSent; + BytesReceived = param.data.radio_stats.params.bytesReceived; + PacketsSent = param.data.radio_stats.params.packetsSent; + PacketsReceived = param.data.radio_stats.params.packetsReceived; + ErrorsSent = param.data.radio_stats.params.errorsSent; + ErrorsReceived = param.data.radio_stats.params.errorsReceived; + DiscardPacketsSent = param.data.radio_stats.params.discardPacketsSent; + DiscardPacketsReceived = param.data.radio_stats.params.discardPacketsReceived; + NoiseFloor = param.data.radio_stats.params.noiseFloor; + radioFirstExTime = time (NULL); + return OK; + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__); + return NOK; + } + +} + +void hostIf_WiFi_Radio_Stats::checkWifiRadioPropsFetch(int radioIndex) +{ + int ret = NOK; + time_t currExTime = time (NULL); + if ((currExTime - radioFirstExTime ) > QUERY_INTERVAL) + { + ret = get_Device_WiFi_Radio_Stats_Props_Fields(radioIndex); + if( OK != ret) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Failed to fetch : %d.\n", __FILE__, __FUNCTION__, ret); + } + } +} + +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_BytesSent(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, BytesSent); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; + +} + + +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_BytesReceived(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, BytesReceived); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_PacketsSent(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, PacketsSent); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_PacketsReceived(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, PacketsReceived); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_ErrorsSent(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, ErrorsSent); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_ErrorsReceived(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, ErrorsReceived); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_DiscardPacketsSent(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, DiscardPacketsSent); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} + +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_DiscardPacketsReceived(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, DiscardPacketsReceived); + stMsgData->paramtype = hostIf_UnsignedIntType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} +int hostIf_WiFi_Radio_Stats::get_Device_WiFi_Radio_Stats_NoiseFloor(HOSTIF_MsgData_t *stMsgData,int radioIndex ) +{ + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + checkWifiRadioPropsFetch(radioIndex); + put_int(stMsgData->paramValue, NoiseFloor); + stMsgData->paramtype = hostIf_IntegerType; + stMsgData->paramLen=4; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; +} +#endif + #endif /* #ifdef USE_WIFI_PROFILE */ diff --git a/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.h b/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.h index 198eb0388..876286d76 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.h +++ b/src/hostif/profiles/wifi/Device_WiFi_Radio_Stats.h @@ -76,6 +76,10 @@ class hostIf_WiFi_Radio_Stats { static GList* getAllAssociateDevs(); static void closeInstance(hostIf_WiFi_Radio_Stats *); static void closeAllInstances(); + #ifdef RDKV_NM + int get_Device_WiFi_Radio_Stats_Props_Fields(int radioIndex); + void checkWifiRadioPropsFetch(int radioIndex); + #endif unsigned long BytesSent; unsigned long BytesReceived; diff --git a/src/hostif/profiles/wifi/Device_WiFi_SSID.cpp b/src/hostif/profiles/wifi/Device_WiFi_SSID.cpp index 1311714d4..6c9e82096 100644 --- a/src/hostif/profiles/wifi/Device_WiFi_SSID.cpp +++ b/src/hostif/profiles/wifi/Device_WiFi_SSID.cpp @@ -37,12 +37,20 @@ *****************************************************************************/ #include #include "safec_lib.h" -#include -#include "cJSON.h" -#include "hostIf_utils.h" #ifdef USE_WIFI_PROFILE #include "Device_WiFi_SSID.h" +#ifdef RDKV_NM +extern "C" { + /* #include "c_only_header.h"*/ +#include "wifi_common_hal.h" +#include "wifiSrvMgrIarmIf.h" +}; +#else +#include +#include "cJSON.h" +#include "hostIf_utils.h" +#endif static time_t firstExTime = 0; @@ -123,7 +131,61 @@ hostIf_WiFi_SSID::hostIf_WiFi_SSID(int dev_id): memset(MACAddress,0, sizeof(MACAddress)); memset(SSID,0, sizeof(SSID)); //CID:103108 - OVERRUN } +#ifdef RDKV_NM +int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Fields(int ssidIndex) +{ + errno_t rc = -1; + IARM_Result_t retVal = IARM_RESULT_SUCCESS; + IARM_BUS_WiFi_DiagsPropParam_t param = {0}; + int ret; + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); + hostIf_WiFi_SSID *pDev = hostIf_WiFi_SSID::getInstance(dev_id); + if (pDev) + { + retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getSSIDProps, (void *)¶m, sizeof(param)); + if (IARM_RESULT_SUCCESS != retVal) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal); + return NOK; + } + rc=strcpy_s(name,sizeof(name),param.data.ssid.params.name); + if(rc!=EOK) + { + ERR_CHK(rc); + } + rc=strcpy_s(BSSID,sizeof(BSSID),param.data.ssid.params.bssid); + if(rc!=EOK) + { + ERR_CHK(rc); + } + rc=strcpy_s(MACAddress,sizeof(MACAddress),param.data.ssid.params.macaddr); + if(rc!=EOK) + { + ERR_CHK(rc); + } + rc=strcpy_s(SSID,sizeof(SSID),param.data.ssid.params.ssid); + if(rc!=EOK) + { + ERR_CHK(rc); + } + rc=strcpy_s(status,sizeof(status),param.data.ssid.params.status); + if(rc!=EOK) + { + ERR_CHK(rc); + } + enable=param.data.ssid.params.enable; + firstExTime = time (NULL); + RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__); + return OK; + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__); + return NOK; + } +} +#else int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Fields(int ssidIndex) { errno_t rc = -1; @@ -133,7 +195,7 @@ int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Fields(int ssidIndex) if (pDev) { std::string postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetConnectedSSID\"}"; - string response = getJsonRPCData(postData); + string response = getJsonRPCData(std::move(postData)); if(response.c_str()) { RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: curl response string = %s\n", __FUNCTION__, response.c_str()); @@ -212,7 +274,7 @@ int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Fields(int ssidIndex) { ERR_CHK(rc); } - cJSON *isEnabled = cJSON_GetObjectItem(interface, "isEnabled"); + cJSON *isEnabled = cJSON_GetObjectItem(interface, "enabled"); enable=isEnabled->type; RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF, "%s: ENABLE = %d \n", __FUNCTION__, enable); } @@ -237,7 +299,7 @@ int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Fields(int ssidIndex) } postData = "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"method\": \"org.rdk.NetworkManager.GetWifiState\"}"; - response = getJsonRPCData(postData); + response = getJsonRPCData(std::move(postData)); if(response.c_str()) { @@ -332,6 +394,7 @@ int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Fields(int ssidIndex) return NOK; } } +#endif void hostIf_WiFi_SSID::checkWifiSSIDFetch(int ssidIndex) { diff --git a/src/hostif/src/IniFile.cpp b/src/hostif/src/IniFile.cpp index df4deb5d8..7c12b7f86 100644 --- a/src/hostif/src/IniFile.cpp +++ b/src/hostif/src/IniFile.cpp @@ -50,7 +50,7 @@ bool IniFile::load(const string &filename) if (splitterPos < line.length()) { string key = line.substr(0, splitterPos); string value = line.substr(splitterPos+1, line.length()); - m_dict[key] = value; + m_dict[key] = std::move(value); } } diff --git a/src/hostif/src/gtest/Makefile.am b/src/hostif/src/gtest/Makefile.am new file mode 100644 index 000000000..abe5dd873 --- /dev/null +++ b/src/hostif/src/gtest/Makefile.am @@ -0,0 +1,37 @@ +################################################################################ +# Copyright 2024 Comcast Cable Communications Management, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +################################################################################ + +AUTOMAKE_OPTIONS = subdir-objects +# Define the program name and the source files +bin_PROGRAMS = src_gtest + +# Define the include directories +COMMON_CPPFLAGS = -std=c++11 -DGTEST_ENABLE -DPARODUS -DUNIT_TEST -I/usr/include -I/usr/include/cjson -I$(TOP_DIR)/src/hostif/include -I$(TOP_DIR)/src/hostif/profiles/DeviceInfo -I$(TOP_DIR)/src/unittest/stubs -I$(TOP_DIR)/src/unittest/stubs/ds -I$(TOP_DIR)/src/unittest/stubs/rbus/include -I$(TOP_DIR)/src/hostif/handlers/include -I$(TOP_DIR)/src/hostif/parodusClient/pal -I$(TOP_DIR)/src/hostif/parodusClient/waldb -I$(TOP_DIR)/src/hostif/httpserver/include -I$(TOP_DIR)/src/hostif/handlers/src -I/usr/include/rbus -I/usr/local/include/rbus -I/usr/include/libsoup-3.0 + +COMMON_LDADD = -lgtest -lgtest_main -lgmock_main -lgmock -lgcov $(GLIB_LIBS) -ltinyxml2 -lcjson -lcurl -lsoup-3.0 + +# Define the compiler flags +COMMON_CXXFLAGS = -frtti $(GLIB_CFLAGS) $(SOUP_LIBS) -fprofile-arcs -ftest-coverage + +# Define the source files +src_gtest_SOURCES = $(TOP_DIR)/src/hostif/src/hostIf_utils.cpp $(TOP_DIR)/src/hostif/src/IniFile.cpp $(TOP_DIR)/src/unittest/stubs/secure_wrapper.c $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFCStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComRFC.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStore.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/XrdkCentralComBSStoreJournal.cpp $(TOP_DIR)/src/hostif/profiles/DeviceInfo/Device_DeviceInfo.cpp $(TOP_DIR)/src/hostif/handlers/src/hostIf_NotificationHandler.cpp $(TOP_DIR)/src/hostif/parodusClient/pal/webpa_notification.cpp $(TOP_DIR)/src/unittest/stubs/dm_stubs.cpp $(TOP_DIR)/src/hostif/parodusClient/waldb/waldb.cpp $(TOP_DIR)/src/unittest/stubs/wdmp-c.c $(TOP_DIR)/src/unittest/stubs/wdmp_internal.c $(TOP_DIR)/src/hostif/httpserver/src/http_server.cpp $(TOP_DIR)/src/hostif/httpserver/src/request_handler.cpp $(TOP_DIR)/src/hostif/httpserver/src/XrdkCentralComRFCVar.cpp $(TOP_DIR)/src/unittest/stubs/file_writer.cpp $(TOP_DIR)/src/hostif/src/gtest/gtest_src.cpp + +# Apply common properties to each program +src_gtest_CPPFLAGS = $(COMMON_CPPFLAGS) +src_gtest_LDADD = $(COMMON_LDADD) +src_gtest_CXXFLAGS = $(COMMON_CXXFLAGS) diff --git a/src/hostif/src/gtest/gtest_src.cpp b/src/hostif/src/gtest/gtest_src.cpp new file mode 100644 index 000000000..639b3f0a8 --- /dev/null +++ b/src/hostif/src/gtest/gtest_src.cpp @@ -0,0 +1,470 @@ +#include +#include +#include "hostIf_tr69ReqHandler.h" +#include "hostIf_utils.h" +#include "XrdkCentralComRFCStore.h" +#include "XrdkCentralComBSStore.h" +#include "XrdkCentralComBSStoreJournal.h" +#include "Device_DeviceInfo_Processor.h" +#include "Device_DeviceInfo_ProcessStatus.h" +#include "XrdkCentralComRFCVar.h" +#include "request_handler.h" +#include "IniFile.h" +#include "hostIf_utils.h" +#include "hostIf_main.h" +#include "webpa_notification.h" +#include "webpa_parameter.h" +#include "rbus_value.h" + +#include "hostIf_msgHandler.h" +#include "http_server.h" +#include "request_handler.h" +#include "rdk_debug.h" +#include "waldb.h" +#include "file_writer.h" + + +#ifdef __cplusplus +extern "C" +{ +#endif +#include +#include +#ifdef __cplusplus +} +#endif + +#include "Device_DeviceInfo.h" + +#include +#include "cJSON.h" + +#include +#include + +#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/" +#define GTEST_DEFAULT_RESULT_FILENAME "hostif_gtest_report.json" +#define GTEST_REPORT_FILEPATH_SIZE 128 + +using namespace std; + +#ifdef GTEST_ENABLE +extern size_t (*getWriteCurlResponse(void))(void *ptr, size_t size, size_t nmemb, std::string stream); +#endif + +XRFCStore* m_rfcStore; +XBSStore* m_bsStore; +XBSStoreJournal* m_bsStoreJournal; +XRFCVarStore* m_varStore; + +std::mutex mtx_httpServerThreadDone; +std::condition_variable cv_httpServerThreadDone; +bool httpServerThreadDone = false; +GThread *HTTPServerThread = NULL; +char *HTTPServerName = (char *)"HTTPServerThread"; +GError *httpError = NULL; +T_ARGLIST argList = {{'\0'}, 0}; + +TEST(srcTest, load) { + IniFile* m_ini = new IniFile(); + const string filename = "/opt/secure/RFC/bootstrap.ini"; + bool result = m_ini->load(filename); + EXPECT_EQ(result, true); + delete m_ini; +} + +TEST(srcTest, inValidFile) { + IniFile* m_ini = new IniFile(); + const string filename = "/opt/secure/RFC/bootstrap_test.ini"; + bool result = m_ini->load(filename); + EXPECT_EQ(result, false); + delete m_ini; +} + +TEST(srcTest, value) { + IniFile* m_ini = new IniFile(); + const string key = "Device.Time.NTPServer5"; + const string defaultValue = "time"; + + bool ret = m_ini->load("/opt/secure/RFC/bootstrap.ini"); + string result = m_ini->value(key, defaultValue); + EXPECT_EQ(result, "override_time4.com"); + delete m_ini; +} + +TEST(srcTest, srcsetValue) { + IniFile* m_ini = new IniFile(); + const string key = "Device.Time.NTPServer4"; + const string value = "overidetime3.com"; + + bool ret = m_ini->load("/opt/secure/RFC/bootstrap.ini"); + bool result = m_ini->setValue(key, value); + EXPECT_EQ(result, true); + delete m_ini; +} + +TEST(srcTest, srcsetDefaultValue) { + IniFile* m_ini = new IniFile(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId"; + const string value = "sky"; + + bool result = m_ini->setValue(key, value); + EXPECT_EQ(result, false); + delete m_ini; +} + +TEST(srcTest, flush) { + IniFile* m_ini = new IniFile(); + const string key = "Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId"; + const string value = "sky"; + + m_ini->m_filename = "/opt/secure/RFC_test/bootstrap_temp.ini"; + bool result = m_ini->flush(); + EXPECT_EQ(result, false); + delete m_ini; +} + +/* TEST(srcTest, clear) { + IniFile *inFile = new IniFile(); + inFile->load("/opt/secure/RFC/bootstrap.ini"); + bool result = inFile->clear(); + EXPECT_EQ(result, true); +} */ + +TEST(srcTest, getStringFromEnum) { + EnumStringMapper myEnumMap[] = { + {0, "ZERO"}, + {1, "ONE"}, + {2, "TWO"}, + {3, "THREE"} + }; + + int size = sizeof(myEnumMap) / sizeof(myEnumMap[0]); + int inputCode = 2; + + const char *result = getStringFromEnum(myEnumMap, size, inputCode); + EXPECT_EQ(result, "TWO"); + + const char *ret = getStringFromEnum(myEnumMap, 0, inputCode); +} + +TEST(srcTest, getEnumFromString) { + EnumStringMapper myEnumMap[] = { + {0, "ZERO"}, + {1, "ONE"}, + {2, "TWO"}, + {3, "THREE"} + }; + + int size = sizeof(myEnumMap) / sizeof(myEnumMap[0]); + + int ret = getEnumFromString(myEnumMap, size, "THREE"); + EXPECT_EQ(ret, 3); + + int result = getEnumFromString(myEnumMap, 0, "THREE"); + EXPECT_EQ(result, -1); +} + +TEST(srcTest, type_conversions) { + int d = 100; + string itosret = int_to_string(d); + EXPECT_EQ(itosret, "100"); + + uint unum = 143; + string uitosret = uint_to_string(unum); + EXPECT_EQ(uitosret, "143"); + + unsigned long ulnum = 123456789UL; + string ultosret = ulong_to_string(ulnum); + EXPECT_EQ(ultosret, "123456789"); + + int num = 42; + const char* ptr = (const char*)# + int iret = get_int(ptr); + EXPECT_EQ(iret, 42); + + uint number = 123456; + char *uptr = (char *)&number; + uint uiret = get_uint(uptr); + EXPECT_EQ(uiret, number); + + int stoiret = string_to_int("123"); + EXPECT_EQ(stoiret, 123); + + uint stouret = string_to_uint("42"); + EXPECT_EQ(stouret, 42); + + unsigned long stoulret = string_to_ulong("1234"); + EXPECT_EQ(stoulret, 1234); + + bool stobret = string_to_bool("false"); + EXPECT_EQ(stobret, false); +} + +TEST(srcTest, bool_to_string) { + std::string value = bool_to_string(true); + EXPECT_EQ(value, "true"); + + string ret = bool_to_string(false); + EXPECT_EQ(ret, "false"); +} + +TEST(srcTest, string_to_bool) { + bool ret = string_to_bool("false"); + EXPECT_EQ(ret, false); + + bool value = string_to_bool("1"); + EXPECT_EQ(value, true); +} + +TEST(srcTest, getBSUpdateEnum) { + HostIf_Source_Type_t type; + type = getBSUpdateEnum("allUpdate"); + EXPECT_EQ(type, HOSTIF_SRC_ALL); + + type = getBSUpdateEnum("rfcUpdate"); + EXPECT_EQ(type, HOSTIF_SRC_RFC); + + type = getBSUpdateEnum("default"); + EXPECT_EQ(type, HOSTIF_SRC_DEFAULT); + + type = getBSUpdateEnum("none"); + EXPECT_EQ(type, HOSTIF_NONE); + + type = getBSUpdateEnum(NULL); + EXPECT_EQ(type, HOSTIF_NONE); +} + + +TEST(srcTest, isWebpaReady) { + bool ret = isWebpaReady(); + EXPECT_EQ(ret, true); +} + +TEST(srcTest, isNtpTimeFilePresent) { + bool ret = isNtpTimeFilePresent(); + EXPECT_EQ(ret, true); +} + +TEST(srcTest, get_system_manageble_ntp_time) { + write_on_file("/tmp/timeReceivedNTP", "Mon Aug 11 14:22:30 UTC 2025"); + unsigned long ret = get_system_manageble_ntp_time(); + EXPECT_EQ(ret, 1754922150); +} + +TEST(srcTest, get_device_manageble_time) { + write_on_file("/tmp/webpa/start_time", "1754835750"); + unsigned long ret = get_device_manageble_time(); + EXPECT_EQ(ret, 1754835750); +} + + +TEST(srcTest, set_get_GatewayConnStatus) { + set_GatewayConnStatus(true); + bool status = get_GatewayConnStatus(); + EXPECT_EQ(status, true); +} + +TEST(srcTest, set_get_LegacyRFCEnabled) { + setLegacyRFCEnabled(true); + bool status = legacyRFCEnabled(); + EXPECT_EQ(status, true); +} + +TEST(srcTest, matchComponent) { + const char* param = "Device.WiFi.SSID.3.SSID"; + const char* key = "Device.WiFi.SSID"; + const char* setting = nullptr; + int instance = 0; + bool matched = matchComponent(param, key, &setting, instance); + EXPECT_EQ(matched, true); +} + +TEST(srcTest, getJsonRPCData) { + std::string jsonRequest = "{\"jsonrpc\":\"2.0\",\"method\":\"getTime\",\"params\":{},\"id\":1}"; + string result = getJsonRPCData(jsonRequest); + EXPECT_EQ(0, 0); +} + +TEST(srcTest, timeValDiff) { + struct timespec starttime = { + .tv_sec = 100, + .tv_nsec = 500000000 // 0.5 seconds + }; + + struct timespec endtime = { + .tv_sec = 102, + .tv_nsec = 200000000 // 0.2 seconds + }; + + long msec = timeValDiff(&starttime, &endtime); + EXPECT_EQ(msec, 1700); +} + +TEST(srcTest, writeCurlResponse) { + const char* input = "MockCurlData"; + size_t size = 1; + size_t nmemb = strlen(input); + std::string response; + size_t written = getWriteCurlResponse()((void*)input, size, nmemb, response); + EXPECT_EQ(written, nmemb); +} + +TEST(srcTest, getCurrentTime) { + struct timespec ts; + getCurrentTime(&ts); + EXPECT_GT(ts.tv_sec, 0); + + EXPECT_GE(ts.tv_nsec, 0); + EXPECT_LT(ts.tv_nsec, 1000000000L); + +} + +TEST(srcTest, ReturnsEnvValueIfSet) +{ + const char* envName = "TEST_ENV_VAR"; + const char* envValue = "expected_value"; + const char* defaultValue = "default_value"; + + // Set environment variable + setenv(envName, envValue, 1); + + // Call function + char* result = getenvOrDefault(envName, defaultValue); + + // Validate + EXPECT_EQ(std::string(result), std::string(envValue)); +} + + +TEST(srcTest, triggerResetScript) +{ + setResetState(ColdReset); + triggerResetScript(); + + setResetState(FactoryReset); + triggerResetScript(); + + setResetState(WarehouseReset); + triggerResetScript(); + + setResetState(CustomerReset); + triggerResetScript(); + + EXPECT_EQ(0, 0); +} + +TEST(srcTest, getResetState) +{ + setResetState(FactoryReset); + eSTBResetState state = getResetState(); + EXPECT_EQ(state, FactoryReset); +} + +TEST(srcTest, get_security_token) +{ + std::string token = get_security_token(); + EXPECT_EQ(token, ""); +} + +TEST(srcTest, putBoolValue) +{ + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + putValue(¶m, "true"); + cout << "msgData.paramValue = " << get_boolean(param.paramValue) << endl; + EXPECT_EQ(get_boolean(param.paramValue), true); +} + +TEST(srcTest, putIntValue) +{ + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_IntegerType; + param.paramLen = sizeof(hostIf_IntegerType); + + putValue(¶m, "14200"); + cout << "msgData.paramValue = " << get_int(param.paramValue) << endl; + EXPECT_EQ(get_int(param.paramValue), 14200); +} + +TEST(srcTest, putStringValue) +{ + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerProductName", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_StringType; + param.paramLen = strlen(param.paramValue); + + putValue(¶m, "testName"); + cout << "msgData.paramValue = " << param.paramValue << endl; + EXPECT_STREQ(param.paramValue, "testName"); +} + +TEST(srcTest, putUnsignedValue) +{ + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.IP.Interface.1.Stats.BytesReceived", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + param.paramtype = hostIf_UnsignedLongType; + param.paramLen = sizeof(hostIf_UnsignedLongType); + + putValue(¶m, "1048576"); + cout << "msgData.paramValue = " << get_ulong(param.paramValue) << endl; + EXPECT_EQ(get_ulong(param.paramValue), 1048576); +} + +TEST(srcTest, ReturnsTrueWhenInputIsTrue) +{ + bool value = true; + EXPECT_EQ(get_boolean((const char *)&value), true); +} + + +TEST(srcTest, getStringValue) +{ + HOSTIF_MsgData_t param = { 0 }; + memset(¶m,0,sizeof(HOSTIF_MsgData_t)); + param.reqType = HOSTIF_GET; + strncpy (param.paramName, "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable", TR69HOSTIFMGR_MAX_PARAM_LEN - 1); + param.bsUpdate = HOSTIF_NONE; + param.requestor = HOSTIF_SRC_RFC; + + put_boolean(param.paramValue, true); + param.paramtype = hostIf_BooleanType; + param.paramLen = sizeof(hostIf_BooleanType); + + std::string value = getStringValue(¶m); + cout << "param.paramValue = " << param.paramValue << endl; + EXPECT_EQ(value, "true"); +} + +GTEST_API_ int main(int argc, char *argv[]){ + char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE]; + char buffer[GTEST_REPORT_FILEPATH_SIZE]; + + memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE ); + memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE ); + snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME); + + ::testing::GTEST_FLAG(output) = testresults_fullfilepath; + ::testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/hostif/src/hostIf_main.cpp b/src/hostif/src/hostIf_main.cpp index 009808fe4..39c451b28 100644 --- a/src/hostif/src/hostIf_main.cpp +++ b/src/hostif/src/hostIf_main.cpp @@ -77,6 +77,10 @@ extern "C" { #include #endif +#ifdef T2_EVENT_ENABLED +#include +#endif + #include "hostIf_rbus_Dml_Provider.h" #include "Device_DeviceInfo.h" #include "safec_lib.h" @@ -107,6 +111,11 @@ static int isShutdownTriggered = 0; #define TV_XML_FILE "/etc/data-model-tv.xml" #define WEBPA_DATA_MODEL_FILE "/tmp/data-model.xml" +#ifdef RDKV_TR69 +#define BASE_DATA_MODEL_FILE "/etc/data-model.xml" +#define INTERMEDIATE_DATA_MODEL_FILE "/tmp/data-model-intermediate.xml" +#endif + std::mutex mtx_httpServerThreadDone; std::condition_variable cv_httpServerThreadDone; @@ -186,7 +195,20 @@ bool GetFeatureEnabled(char *cmd) } #endif +/* Description: Use for sending telemetry Log + * @param marker: use for send marker details + * @return : void + * */ +#ifdef T2_EVENT_ENABLED +void t2CountNotify(const char *marker, int val) { + t2_event_d(marker, val); +} +void t2ValNotify( const char *marker, const char *val ) +{ + t2_event_s(marker, val); +} +#endif //------------------------------------------------------------------------------ @@ -194,189 +216,174 @@ bool GetFeatureEnabled(char *cmd) //------------------------------------------------------------------------------ int main(int argc, char *argv[]) { - int ch = 0; - errno_t rc = -1; -#ifdef WEBPA_RFC_ENABLED - bool retVal=false; -#endif - const char* debugConfigFile = NULL; - const char* webpaNotifyConfigFile = NULL; - //------------------------------------------------------------------------------ - // Signal handlers: - //------------------------------------------------------------------------------ - struct sigaction sigact; - - while (1) + try { - static struct option long_options[] = + int ch = 0; + errno_t rc = -1; + #ifdef WEBPA_RFC_ENABLED + bool retVal=false; + #endif + //------------------------------------------------------------------------------ + // Signal handlers: + //------------------------------------------------------------------------------ + struct sigaction sigact; + + while (1) { - /* These options don't set a flag. - We distinguish them by their indices. */ - {"help", no_argument, 0, 'h'}, - {"logfile", required_argument, 0, 'l'}, - {"conffile", required_argument, 0, 'c'}, - {"port", required_argument, 0, 'p'}, -#ifndef NEW_HTTP_SERVER_DISABLE - {"httpserverport", required_argument, 0, 's'}, -#endif - {"debugconfig", required_argument, 0, 'd'}, - {"notifyconfig", required_argument, 0, 'w'}, - {0, 0, 0, 0} - }; - - /* getopt_long stores the option index here. */ - int option_index = 0; -#ifndef NEW_HTTP_SERVER_DISABLE - ch = getopt_long (argc, argv, "hHl:c:p:s:d:w:", - long_options, &option_index); -#else - ch = getopt_long (argc, argv, "hHl:c:p:d:w:", - long_options, &option_index); -#endif - /* Detect the end of the options. */ - if (ch == -1) - break; + static struct option long_options[] = + { + /* These options don't set a flag. + We distinguish them by their indices. */ + {"help", no_argument, 0, 'h'}, + {"logfile", required_argument, 0, 'l'}, + {"conffile", required_argument, 0, 'c'}, + {"port", required_argument, 0, 'p'}, + #ifndef NEW_HTTP_SERVER_DISABLE + {"httpserverport", required_argument, 0, 's'}, + #endif + {0, 0, 0, 0} + }; + + /* getopt_long stores the option index here. */ + int option_index = 0; + #ifndef NEW_HTTP_SERVER_DISABLE + ch = getopt_long (argc, argv, "hHl:c:p:s:d:w:", + long_options, &option_index); + #else + ch = getopt_long (argc, argv, "hHl:c:p:d:w:", + long_options, &option_index); + #endif + /* Detect the end of the options. */ + if (ch == -1) + break; - switch (ch) - { - case 'c': - if(optarg) + switch (ch) { - memset(argList.confFile, '\0', sizeof (argList.confFile)); - rc=strcpy_s (argList.confFile,sizeof(argList.confFile),optarg); - if(rc!=EOK) - { + case 'c': + if(optarg) + { + memset(argList.confFile, '\0', sizeof (argList.confFile)); + rc=strcpy_s (argList.confFile,sizeof(argList.confFile),optarg); + if(rc!=EOK) + { ERR_CHK(rc); - } -// RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"argList.confFile : %s optarg : %s\n", argList.confFile, optarg); - } - break; + } +// RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"argList.confFile : %s optarg : %s\n", argList.confFile, optarg); + } + break; - case 'd': - if(optarg) - { - debugConfigFile = optarg; - } - break; - case 'w': - if(optarg) - { - webpaNotifyConfigFile = optarg; + case 'p': + if(optarg) + { + argList.httpPort = atoi(optarg); + } + break; + #ifndef NEW_HTTP_SERVER_DISABLE + case 's': + if(optarg) + { + argList.httpServerPort = atoi(optarg); + } + break; + #endif + case 'h': + case 'H': + case '?': + default: + usage(); + exit(0); } - break; + } - case 'p': - if(optarg) - { - argList.httpPort = atoi(optarg); - } - break; -#ifndef NEW_HTTP_SERVER_DISABLE - case 's': - if(optarg) - { - argList.httpServerPort = atoi(optarg); - } - break; -#endif - case 'h': - case 'H': - case '?': - default: + /* Enable RDK logger.*/ + if(rdk_logger_init(0 == access("/opt/debug.ini", R_OK) ? "/opt/debug.ini" : "/etc/debug.ini") == 0) rdk_logger_enabled = 1; + #ifdef T2_EVENT_ENABLED + t2_init(const_cast("tr69hostif")); + #endif + if (optind < argc) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"non-option ARGV-elements: "); + while (optind < argc) + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s ", argv[optind++]); + putchar ('\n'); usage(); - exit(0); - } - } + exit (0); + } - /* Enable RDK logger.*/ - if(rdk_logger_init(debugConfigFile) == 0) rdk_logger_enabled = 1; + #ifdef WEBPA_RFC_ENABLED + retVal = GetFeatureEnabled("WEBPAXG"); + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,"[%s] WEBPAXG returns %d\n", __FUNCTION__, retVal); + if( retVal == false) + { + // Send a notification to systemd to stop the service + int ret = sd_pid_notify(0, SD_FINALIZING); - if (optind < argc) - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"non-option ARGV-elements: "); - while (optind < argc) - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s ", argv[optind++]); - putchar ('\n'); - usage(); - exit (0); - } + if (ret < 0) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error sending stop notification: %s\n", strerror(-ret)); + return 1; + } -#ifdef WEBPA_RFC_ENABLED - retVal = GetFeatureEnabled("WEBPAXG"); - RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,"[%s] WEBPAXG returns %d\n", __FUNCTION__, retVal); - if( retVal == false) - { - // Send a notification to systemd to stop the service - int ret = sd_pid_notify(0, SD_FINALIZING); + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Service stop notification sent successfully.\n"); + return ch; + } + #endif - if (ret < 0) - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error sending stop notification: %s\n", strerror(-ret)); + if (sem_init(&shutdown_thread_sem, 0, 0) == -1) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] sem_init() failed\n", __FUNCTION__, __FILE__); return 1; } - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Service stop notification sent successfully.\n"); - return ch; - } -#endif - - if (sem_init(&shutdown_thread_sem, 0, 0) == -1) - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] sem_init() failed\n", __FUNCTION__, __FILE__); - return 1; - } - - if (pthread_create(&shutdown_thread, NULL, shutdown_thread_entry, NULL) != 0) - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] pthread_create() failed\n", __FUNCTION__, __FILE__); - return 1; - } - - // The actions for SIGINT, SIGTERM, SIGSEGV, and SIGQUIT are set - sigemptyset(&sigact.sa_mask); - sigact.sa_handler = quit_handler; - sigact.sa_flags = SA_ONSTACK; - - sigaction (SIGINT, &sigact, NULL); - sigaction (SIGTERM, &sigact, NULL); - sigaction (SIGHUP, &sigact, NULL); - signal (SIGPIPE, SIG_IGN); - - setvbuf(stdout, NULL, _IOLBF, 0); + if (pthread_create(&shutdown_thread, NULL, shutdown_thread_entry, NULL) != 0) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] pthread_create() failed\n", __FUNCTION__, __FILE__); + return 1; + } - //------------------------------------------------------------------------------ - // Initialize the glib, g_time and logger - //------------------------------------------------------------------------------ -#if GLIB_VERSION_CUR_STABLE <= GLIB_VERSION_2_32 - if(!g_thread_supported()) - { - g_thread_init(NULL); - RDK_LOG(RDK_LOG_NOTICE,LOG_TR69HOSTIF,"g_thread supported\n"); - } - else - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"g_thread NOT supported\n"); - } -#endif - /* Enable RDK logger.*/ - if(rdk_logger_init(debugConfigFile) == 0) rdk_logger_enabled = 1; + // The actions for SIGINT, SIGTERM, SIGSEGV, and SIGQUIT are set + sigemptyset(&sigact.sa_mask); + sigact.sa_handler = quit_handler; + sigact.sa_flags = SA_ONSTACK; -#if defined(USE_WIFI_PROFILE) - /* Perform the necessary operations to initialise the WiFi device */ - (void)WiFiDevice::init(); -#endif -// g_get_current_time(&timeval); -// char* logoutfile = (char *)LOG_FILE; -#if 0 - /* Commented: Since logs are directed to /opt/logs/ folder, - * so no need to use separate log file */ - char* logoutfile = (char *)argList.logFileName; + sigaction (SIGINT, &sigact, NULL); + sigaction (SIGTERM, &sigact, NULL); + sigaction (SIGHUP, &sigact, NULL); + signal (SIGPIPE, SIG_IGN); + setvbuf(stdout, NULL, _IOLBF, 0); - g_log_set_handler(G_LOG_DOMAIN, (GLogLevelFlags)(G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | \ - G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | \ - G_LOG_LEVEL_ERROR), tr69hostIf_logger, (void *)logoutfile); -#endif + //------------------------------------------------------------------------------ + // Initialize the glib, g_time and logger + //------------------------------------------------------------------------------ + #if GLIB_VERSION_CUR_STABLE <= GLIB_VERSION_2_32 + if(!g_thread_supported()) + { + g_thread_init(NULL); + RDK_LOG(RDK_LOG_NOTICE,LOG_TR69HOSTIF,"g_thread supported\n"); + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"g_thread NOT supported\n"); + } + #endif + + #if defined(USE_WIFI_PROFILE) + /* Perform the necessary operations to initialise the WiFi device */ + (void)WiFiDevice::init(); + #endif + // g_get_current_time(&timeval); + // char* logoutfile = (char *)LOG_FILE; + #if 0 + /* Commented: Since logs are directed to /opt/logs/ folder, + * so no need to use separate log file */ + char* logoutfile = (char *)argList.logFileName; + + + g_log_set_handler(G_LOG_DOMAIN, (GLogLevelFlags)(G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | \ + G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | \ + G_LOG_LEVEL_ERROR), tr69hostIf_logger, (void *)logoutfile); + #endif RDK_LOG(RDK_LOG_NOTICE,LOG_TR69HOSTIF,"Starting tr69HostIf Service\n"); @@ -387,158 +394,176 @@ int main(int argc, char *argv[]) based on the group of configuration. */ //if(false == hostIf_ConfigProperties_Init()) - if(false == hostIf_initalize_ConfigManger()) - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed to hostIf_initalize_ConfigManger()\n"); - } + if(false == hostIf_initalize_ConfigManger()) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed to hostIf_initalize_ConfigManger()\n"); + } -#ifndef NEW_HTTP_SERVER_DISABLE - ifstream ifs_legacyEnabled(LEGACY_RFC_ENABLED_PATH); - if(!ifs_legacyEnabled.is_open()) - { - setLegacyRFCEnabled(false); - } - else - { - setLegacyRFCEnabled(true); - ifs_legacyEnabled.close(); - } -#endif + #ifndef NEW_HTTP_SERVER_DISABLE + ifstream ifs_legacyEnabled(LEGACY_RFC_ENABLED_PATH); + if(!ifs_legacyEnabled.is_open()) + { + setLegacyRFCEnabled(false); + } + else + { + setLegacyRFCEnabled(true); + ifs_legacyEnabled.close(); + } + #endif - if(false == hostIf_IARM_IF_Start() ) - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed to start hostIf_IARM_IF_Start()\n"); - } - MergeStatus mergeStatus = mergeDataModel(); - if (mergeStatus != MERGE_SUCCESS) { - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Error in merging Data Model\n"); - return DB_FAILURE; // Or handle the failure appropriately - } - else { - RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "Successfully merged Data Model.\n"); - } - /* Load the data model xml file*/ - DB_STATUS status = loadDataModel(); - if(status != DB_SUCCESS) - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error in Data Model Initialization\n"); - return DB_FAILURE; - } - else - { - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Successfully initialize Data Model.\n"); - } + if(false == hostIf_IARM_IF_Start() ) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed to start hostIf_IARM_IF_Start()\n"); + } + MergeStatus mergeStatus = mergeDataModel(); + if (mergeStatus != MERGE_SUCCESS) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Error in merging Data Model\n"); + return DB_FAILURE; // Or handle the failure appropriately + } + else { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "Successfully merged Data Model.\n"); + } + /* Load the data model xml file*/ + DB_STATUS status = loadDataModel(); + if(status != DB_SUCCESS) + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error in Data Model Initialization\n"); + return DB_FAILURE; + } + else + { + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Successfully initialize Data Model.\n"); + } //------------------------------------------------------------------------------ // hostIf_HttpServerStart: Soup HTTP Server //------------------------------------------------------------------------------ - if( (hostIf_JsonIfThread = g_thread_try_new( "json_if_handler_thread", (GThreadFunc)jsonIfHandlerThread, (void *)hostIf_JsonIfMsg, &err1)) == NULL) - { - g_critical("Thread create failed: %s!!\n", err1->message ); - g_error_free (err1); - } -#ifndef NEW_HTTP_SERVER_DISABLE - if(!legacyRFCEnabled()) - { - RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"legacyRFC Set to False, Starting New HTTP Server\n"); - if((HTTPServerThread = g_thread_try_new("http_server_thread", (GThreadFunc)HTTPServerStartThread, (void *)HTTPServerName, &httpError)) == NULL) + if( (hostIf_JsonIfThread = g_thread_try_new( "json_if_handler_thread", (GThreadFunc)jsonIfHandlerThread, (void *)hostIf_JsonIfMsg, &err1)) == NULL) + { + g_critical("Thread create failed: %s!!\n", err1->message ); + g_error_free (err1); + } + #ifndef NEW_HTTP_SERVER_DISABLE + if(!legacyRFCEnabled()) { - g_critical("New HTTP Server Thread Create failed: %s!!\n", httpError->message ); - g_error_free (httpError); + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"legacyRFC Set to False, Starting New HTTP Server\n"); + if((HTTPServerThread = g_thread_try_new("http_server_thread", (GThreadFunc)HTTPServerStartThread, (void *)HTTPServerName, &httpError)) == NULL) + { + g_critical("New HTTP Server Thread Create failed: %s!!\n", httpError->message ); + g_error_free (httpError); + } } - } - else - { - RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"legacyRFC Set to True, New HTTP Server is not started\n"); - } -#endif + else + { + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"legacyRFC Set to True, New HTTP Server is not started\n"); + } + #endif + + #ifdef PID_FILE_PATH + #define xstr(s) str(s) + #define str(s) #s + // write pidfile because sd_notify() does not work inside container + IARM_Bus_WritePIDFile(xstr(PID_FILE_PATH) "/tr69hostif.pid"); + #endif + + //------------------------------------------------------------------------------ + // updateHandler::init : Update handler thread for polling table profiles + //------------------------------------------------------------------------------ + updateHandler::Init(); + + #if defined(PARODUS_ENABLE) + //------------------------------------------------------------------------------ + // Initialize WebPA Module + //------------------------------------------------------------------------------ + + RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Starting WEBPA Parodus Connections\n"); + libpd_set_notifyConfigFile(0 == access("/opt/notify_webpa_cfg.json", R_OK) ? "/opt/notify_webpa_cfg.json" : "/etc/notify_webpa_cfg.json"); + if(0 == pthread_create(&parodus_init_tid, NULL, libpd_client_mgr, NULL)) + { + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Initiating Connection with PARODUS success.. \n"); + } + else + { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Parodus init thread create failed\n"); + } + #endif -#ifdef PID_FILE_PATH -#define xstr(s) str(s) -#define str(s) #s - // write pidfile because sd_notify() does not work inside container - IARM_Bus_WritePIDFile(xstr(PID_FILE_PATH) "/tr69hostif.pid"); -#endif + #if defined(WEB_CONFIG_ENABLED) + initWebConfigMultipartTask(0); + #elif defined(WEBCONFIG_LITE_ENABLE) + if(0 == pthread_create(&webconfig_threadId, NULL, initWebConfigTask, NULL)) + { + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"webconfig thread created success.. \n"); + } + else + { + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"webconfig thread created failed.. \n"); + } + #endif - //------------------------------------------------------------------------------ - // updateHandler::init : Update handler thread for polling table profiles - //------------------------------------------------------------------------------ - updateHandler::Init(); + /* Initialized Rbus interface for TR181 Data*/ + init_rbus_dml_provider(); -#if defined(PARODUS_ENABLE) - //------------------------------------------------------------------------------ - // Initialize WebPA Module - //------------------------------------------------------------------------------ + // Send sd notify event after http server thread is complete. + if (httpServerThreadDone == false) + { + std::unique_lock lck(mtx_httpServerThreadDone); + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Waiting(max 10 sec) for http server thread to be complete...\n"); + auto sec = chrono::seconds(1); + cv_httpServerThreadDone.wait_for(lck, 10*sec, [] {return httpServerThreadDone;}); + } + #ifdef ENABLE_SD_NOTIFY + sd_notifyf(0, "READY=1\n" + "STATUS=tr69hostif is Successfully Initialized\n" + "MAINPID=%lu", (unsigned long) getpid()); + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"tr69hostif sd notify envent is sent Successfully, httpServerThreadDone=%d\n", httpServerThreadDone); + #endif - RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Starting WEBPA Parodus Connections\n"); - libpd_set_notifyConfigFile(webpaNotifyConfigFile); - if(0 == pthread_create(&parodus_init_tid, NULL, libpd_client_mgr, NULL)) - { - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Initiating Connection with PARODUS success.. \n"); - } - else - { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Parodus init thread create failed\n"); - } -#endif + hostIf_DeviceInfo::send_DeviceManageableNotification(); -#if defined(WEB_CONFIG_ENABLED) - initWebConfigMultipartTask(0); -#elif defined(WEBCONFIG_LITE_ENABLE) - if(0 == pthread_create(&webconfig_threadId, NULL, initWebConfigTask, NULL)) - { - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"webconfig thread created success.. \n"); + main_loop = g_main_loop_new (NULL, FALSE); + + if(main_loop) { + g_main_loop_run(main_loop); + g_main_loop_unref (main_loop); + } + else { + RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s]Fails to Create a main loop.", __FUNCTION__); + } + if (isShutdownTriggered) + return 0; + + if(hostIf_JsonIfThread) + g_thread_join(hostIf_JsonIfThread); + + #ifndef NEW_HTTP_SERVER_DISABLE + if(HTTPServerThread) + g_thread_join(HTTPServerThread); + #endif + #if defined(PARODUS_ENABLE) + if(parodus_init_tid) + pthread_join(parodus_init_tid,NULL); + #endif + + RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"\n\n----------------------EXITING MAIN PROGRAM----------------------\n"); + return 0 ; } - else + catch (const std::bad_cast& e) { - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"webconfig thread created failed.. \n"); + std::cerr << "Bad cast exception: " << e.what() << std::endl; + return 1; } -#endif - - /* Initialized Rbus interface for TR181 Data*/ - init_rbus_dml_provider(); - - // Send sd notify event after http server thread is complete. - if (httpServerThreadDone == false) + catch (const std::exception& e) { - std::unique_lock lck(mtx_httpServerThreadDone); - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Waiting(max 10 sec) for http server thread to be complete...\n"); - auto sec = chrono::seconds(1); - cv_httpServerThreadDone.wait_for(lck, 10*sec, [] {return httpServerThreadDone;}); - } -#ifdef ENABLE_SD_NOTIFY - sd_notifyf(0, "READY=1\n" - "STATUS=tr69hostif is Successfully Initialized\n" - "MAINPID=%lu", (unsigned long) getpid()); - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"tr69hostif sd notify envent is sent Successfully, httpServerThreadDone=%d\n", httpServerThreadDone); -#endif - - hostIf_DeviceInfo::send_DeviceManageableNotification(); - - main_loop = g_main_loop_new (NULL, FALSE); - - if(main_loop) { - g_main_loop_run(main_loop); - g_main_loop_unref (main_loop); + std::cerr << "Exception: " << e.what() << std::endl; + return 1; } - else { - RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s]Fails to Create a main loop.", __FUNCTION__); + catch (...) + { + std::cerr << "Unknown exception occurred" << std::endl; + return 1; } - - if(hostIf_JsonIfThread) - g_thread_join(hostIf_JsonIfThread); - -#ifndef NEW_HTTP_SERVER_DISABLE - if(HTTPServerThread) - g_thread_join(HTTPServerThread); -#endif -#if defined(PARODUS_ENABLE) - if(parodus_init_tid) - pthread_join(parodus_init_tid,NULL); -#endif - - RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"\n\n----------------------EXITING MAIN PROGRAM----------------------\n"); - return 0 ; } //------------------------------------------------------------------------------ @@ -576,7 +601,9 @@ void exit_gracefully (int sig_received) if(pthread_mutex_trylock(&graceful_exit_mutex) == 0) { RDK_LOG(RDK_LOG_NOTICE,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__); isShutdownTriggered = 1; - +#ifdef T2_EVENT_ENABLED + t2_uninit(); +#endif #if defined(USE_WIFI_PROFILE) /* Perform the necessary operations to shut down the WiFi device */ WiFiDevice::shutdown(); @@ -650,8 +677,77 @@ static void usage() \n" << endl; #endif } +#ifdef RDKV_TR69 +MergeStatus mergeDataModelRDKV(const char* rdk_profile) { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "RDKV: First merging base data-model.xml with data-model-generic.xml\n"); + const char *base_file = BASE_DATA_MODEL_FILE; + const char *generic_file = GENERIC_XML_FILE; + const char *intermediate_file = INTERMEDIATE_DATA_MODEL_FILE; + const char *output_file = WEBPA_DATA_MODEL_FILE; + + // Step 1: Merge base data-model.xml with data-model-generic.xml + if (!filter_and_merge_xml(generic_file, base_file, intermediate_file)) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "RDKV: Error while merging base data-model.xml with data-model-generic.xml\n"); + return MERGE_FAILURE; + } + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "RDKV: Successfully created intermediate merged file\n"); + + // Step 2: Apply profile-specific merging using the intermediate file as base + if (strcmp(rdk_profile, "TV") == 0) { + const char *tv_file = TV_XML_FILE; + if (!filter_and_merge_xml(tv_file, intermediate_file, output_file)) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "RDKV: Error while merging with TV profile\n"); + return MERGE_FAILURE; + } + } + else if (strcmp(rdk_profile, "STB") == 0) { + const char *stb_file = STB_XML_FILE; + if (!filter_and_merge_xml(stb_file, intermediate_file, output_file)) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "RDKV: Error while merging with STB profile\n"); + return MERGE_FAILURE; + } + } + else { + // If no specific profile, just use the intermediate file as final + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "RDKV: No specific profile, using intermediate file as final\n"); + if (rename(intermediate_file, output_file) != 0) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "RDKV: Error moving intermediate file to final location\n"); + return MERGE_FAILURE; + } + } - + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "RDKV: Merged XML written to %s\n", output_file); + return MERGE_SUCCESS; +} +#else +MergeStatus mergeDataModelRDKE(const char* rdk_profile) { + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "RDKE: Merging XML files for profile: %s\n", rdk_profile); + const char *generic_file = GENERIC_XML_FILE; + const char *output_file = WEBPA_DATA_MODEL_FILE; + + if (strcmp(rdk_profile, "TV") == 0) { + const char *tv_file = TV_XML_FILE; + if (!filter_and_merge_xml(generic_file, tv_file, output_file)) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "RDKE: Error while merging XML files for TV profile\n"); + return MERGE_FAILURE; + } + } + else if (strcmp(rdk_profile, "STB") == 0) { + const char *stb_file = STB_XML_FILE; + if (!filter_and_merge_xml(generic_file, stb_file, output_file)) { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "RDKE: Error while merging XML files for STB profile\n"); + return MERGE_FAILURE; + } + } + else { + RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "RDKE: Unsupported RDK_PROFILE: %s\n", rdk_profile); + return MERGE_FAILURE; + } + + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "RDKE: Merged XML written to %s\n", output_file); + return MERGE_SUCCESS; +} +#endif bool filter_and_merge_xml(const char *input1, const char *input2, const char *output) { FILE *in_fp1 = fopen(input1, "r"); FILE *in_fp2 = fopen(input2, "r"); @@ -718,7 +814,7 @@ return true; MergeStatus mergeDataModel() { - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Entering \n"); + RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "Entering data model merge process\n"); FILE *fp = fopen(DEVICE_PROPS_FILE, "r"); if (fp != NULL) { char line[256]; @@ -733,29 +829,15 @@ MergeStatus mergeDataModel() { } } fclose(fp); - RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "mergeDataModel: Closed /etc/device.properties\n"); - const char *generic_file = GENERIC_XML_FILE; - const char *output_file = WEBPA_DATA_MODEL_FILE; - if (strcmp(rdk_profile, "TV") == 0) { - const char *tv_file = TV_XML_FILE; - if (!filter_and_merge_xml(generic_file, tv_file, output_file)) { - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Error while merging XML files for TV profile\n"); - return MERGE_FAILURE; - } - } - else if (strcmp(rdk_profile, "STB") == 0) { - const char *stb_file = STB_XML_FILE; - if (!filter_and_merge_xml(generic_file, stb_file, output_file)) { - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Error while merging XML files for STB profile\n"); - return MERGE_FAILURE; - } - } - else { - RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Unsupported RDK_PROFILE: %s\n", rdk_profile); - return MERGE_FAILURE; - } - RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF, "Merged XML written to %s\n", output_file); - return MERGE_SUCCESS; + RDK_LOG(RDK_LOG_DEBUG, LOG_TR69HOSTIF, "mergeDataModel: Closed /etc/device.properties, Profile: %s\n", rdk_profile); + +#ifdef RDKV_TR69 + // Use RDKV-specific merging logic + return mergeDataModelRDKV(rdk_profile); +#else + // Use RDKE-specific merging logic + return mergeDataModelRDKE(rdk_profile); +#endif } else { diff --git a/src/hostif/src/hostIf_utils.cpp b/src/hostif/src/hostIf_utils.cpp index 6cc33f430..68627f913 100644 --- a/src/hostif/src/hostIf_utils.cpp +++ b/src/hostif/src/hostIf_utils.cpp @@ -541,16 +541,15 @@ std::string get_security_token() { } else { RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] json parse error\n", __FUNCTION__); - if (NULL != pSecurity) - v_secure_pclose(pSecurity); } - } + } + v_secure_pclose(pSecurity); } + else { RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,"%s: Failed to open security utility\n", __FUNCTION__); } - if (NULL != pSecurity) - v_secure_pclose(pSecurity); + return sToken; } @@ -644,5 +643,11 @@ string getJsonRPCData(std::string postData) } } +#ifdef GTEST_ENABLE +size_t (*getWriteCurlResponse(void))(void *ptr, size_t size, size_t nmemb, std::string stream) { + return &writeCurlResponse; +} +#endif + /** @} */ /** @} */ diff --git a/src/integrationtest/conf/bootstrap.ini b/src/integrationtest/conf/bootstrap.ini index 2c68c633c..99467fef3 100644 --- a/src/integrationtest/conf/bootstrap.ini +++ b/src/integrationtest/conf/bootstrap.ini @@ -1 +1,2 @@ Device.DeviceInfo.X_RDKCENTRAL-COM_Syndication.PartnerId=global +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName=comcast diff --git a/src/integrationtest/conf/data-model-generic.xml b/src/integrationtest/conf/data-model-generic.xml deleted file mode 100755 index 13dfcc5cd..000000000 --- a/src/integrationtest/conf/data-model-generic.xml +++ /dev/null @@ -1,4422 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/integrationtest/conf/rfcVariable.ini b/src/integrationtest/conf/rfcVariable.ini new file mode 100644 index 000000000..a1d29a81d --- /dev/null +++ b/src/integrationtest/conf/rfcVariable.ini @@ -0,0 +1,2 @@ +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.IssueType=testtype +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.WebCfgData=testCfg diff --git a/src/unittest/stubs/dm_stubs.cpp b/src/unittest/stubs/dm_stubs.cpp index 834dc7d7c..c8f59d54d 100644 --- a/src/unittest/stubs/dm_stubs.cpp +++ b/src/unittest/stubs/dm_stubs.cpp @@ -22,7 +22,9 @@ #include "hostIf_main.h" #include "XrdkCentralComRFCStore.h" #include "rbus.h" +#include "power_controller.h" +#ifdef PARODUS rbusHandle_t rbusHandle = NULL; int hostIf_GetMsgHandler(HOSTIF_MsgData_t *stMsgData) { @@ -53,6 +55,9 @@ int hostIf_SetMsgHandler(HOSTIF_MsgData_t *stMsgData) * for wildcards request where it represents the number of param/value pairs retrieved for the particular wildcard parameter. * @param[out] retStatus List of Return status. */ +#endif + +#ifdef UNIT_TEST void getValues (const char *paramName[], const unsigned int paramCount, param_t ***paramValArr,size_t **retValCount, WDMP_STATUS **retStatus) { @@ -68,7 +73,7 @@ void setValues(const ParamVal paramVal[], const unsigned int paramCount, const W { } - +#endif IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *arg, size_t argLen) { return IARM_RESULT_SUCCESS; @@ -109,6 +114,37 @@ IARM_Result_t IARM_Bus_Call(const char* ownerName, const char* methodName, void* return IARM_RESULT_SUCCESS; } + +void PowerController_Init() +{ + +} + +void PowerController_Term() +{ + +} + +uint32_t PowerController_Connect() +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_RegisterPowerModeChangedCallback(PowerController_PowerModeChangedCb callback, void* userdata) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_UnRegisterPowerModeChangedCallback(PowerController_PowerModeChangedCb callback) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_GetPowerState(PowerController_PowerState_t* currentState, PowerController_PowerState_t* previousState) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + rbusValue_t rbusValue_Init(rbusValue_t* value) { return NULL; @@ -124,7 +160,6 @@ void rbusObject_SetValue(rbusObject_t object, char const* var, rbusValue_t value return; } - void rbusValue_Release(rbusValue_t value) { return; diff --git a/src/unittest/stubs/ds/aspectRatio.hpp b/src/unittest/stubs/ds/aspectRatio.hpp index 6dac1e1a4..0bbdb5314 100644 --- a/src/unittest/stubs/ds/aspectRatio.hpp +++ b/src/unittest/stubs/ds/aspectRatio.hpp @@ -54,11 +54,15 @@ class AspectRatio : public DSConstant { static const int k16x9; //!< Indicates 16x9 aspect ratio. static const int kMax; //!< Indicates maximum number of aspect ratios supported. - static const AspectRatio & getInstance(int id); + static const AspectRatio & getInstance(int id) + { + static AspectRatio aspectRatio(id); + return aspectRatio; + } static const AspectRatio & getInstance(const std::string &name); - AspectRatio(int id); - virtual ~AspectRatio(); + AspectRatio(int id) {} + virtual ~AspectRatio() {} }; diff --git a/src/unittest/stubs/ds/audioEncoding.hpp b/src/unittest/stubs/ds/audioEncoding.hpp index 800359bec..e3771ccd2 100644 --- a/src/unittest/stubs/ds/audioEncoding.hpp +++ b/src/unittest/stubs/ds/audioEncoding.hpp @@ -51,17 +51,17 @@ namespace device { class AudioEncoding : public DSConstant { public: - static const int kNone; //!< Value indicating encoding type None. - static const int kDisplay; //!< Value indicating digital audio encoding format. - static const int kPCM; //!< Value indicating PCM digital audio encoding format. - static const int kAC3; //!< Value indicating AC3 digital audio encoding format. - static const int kMax; //!< Indicates the maximum encoding formats supported. + static constexpr int kNone = 0; //!< Value indicating encoding type None. + static constexpr int kDisplay = 1; //!< Value indicating digital audio encoding format. + static constexpr int kPCM = 2; //!< Value indicating PCM digital audio encoding format. + static constexpr int kAC3 = 3; //!< Value indicating AC3 digital audio encoding format. + static constexpr int kMax = 4; //!< Indicates the maximum encoding formats supported. static const AudioEncoding & getInstance(int id); static const AudioEncoding & getInstance(const std::string &name); - AudioEncoding(int id); - virtual ~AudioEncoding(); + AudioEncoding(int id) {} + virtual ~AudioEncoding() {} }; diff --git a/src/unittest/stubs/ds/audioOutputPort.hpp b/src/unittest/stubs/ds/audioOutputPort.hpp index 073740291..9bf77c587 100644 --- a/src/unittest/stubs/ds/audioOutputPort.hpp +++ b/src/unittest/stubs/ds/audioOutputPort.hpp @@ -84,11 +84,16 @@ class AudioOutputPort : public Enumerable { public: - static AudioOutputPort & getInstance(int id); + static AudioOutputPort & getInstance(int id) + { + static AudioOutputPort instance(id); + return instance; + } static AudioOutputPort & getInstance(const std::string &name); AudioOutputPort(const int type, const int index, const int id); - virtual ~AudioOutputPort(); + AudioOutputPort(int id) {} + virtual ~AudioOutputPort() {} const AudioOutputPortType & getType() const; int getId() const {return _id;}; @@ -108,9 +113,13 @@ class AudioOutputPort : public Enumerable { const List getSupportedStereoModes() const; - const AudioEncoding &getEncoding() const; - int getCompression() const; - int getDialogEnhancement() const; + const AudioEncoding &getEncoding() const + { + static AudioEncoding audioObj(AudioEncoding::kPCM); + return audioObj; + } + int getCompression() const { return 1; } + int getDialogEnhancement() const { return 1; } bool getDolbyVolumeMode() const; int getIntelligentEqualizerMode() const; dsVolumeLeveller_t getVolumeLeveller() const; @@ -122,7 +131,11 @@ class AudioOutputPort : public Enumerable { int getGraphicEqualizerMode() const; const std::string getMS12AudioProfile() const; std::vector getMS12AudioProfileList() const; - const AudioStereoMode &getStereoMode(bool usePersist = false); + const AudioStereoMode &getStereoMode(bool usePersist = false) + { + static AudioStereoMode stereoObj(AudioStereoMode::kStereo); + return stereoObj; + } dsError_t setEnablePort(bool enabled); dsError_t reInitializeAudioOutputPort(); @@ -134,25 +147,25 @@ class AudioOutputPort : public Enumerable { bool getStereoAuto(); - float getGain() const; - float getDB() const; - float getLevel() const; - float getMaxDB() const; - float getMinDB() const; - float getOptimalLevel() const; + float getGain() const { return 0.6f; }; + float getDB() const { return 0.6f; }; + float getLevel() const { return 0.6f; }; + float getMaxDB() const { return 0.6f; }; + float getMinDB() const { return 0.6f; }; + float getOptimalLevel() const { return 0.6f; }; bool getAudioDelay(uint32_t& audioDelayMs) const; bool getAudioDelayOffset(uint32_t& audioDelayOffsetMs) const; - bool isLoopThru() const; - bool isMuted() const; + bool isLoopThru() const { return true; } + bool isMuted() const { return true; }; bool isConnected() const; - bool isEnabled() const; + bool isEnabled() const { return true; }; bool isAudioMSDecode() const; bool isAudioMS12Decode() const; - void setEncoding(const int encoding); - void setCompression(const int compression); - void setDialogEnhancement(const int level); + void setEncoding(const int encoding) {} + void setCompression(const int compression) {} + void setDialogEnhancement(const int level) {} void setDolbyVolumeMode(const bool mode); void setIntelligentEqualizerMode(const int mode); void setVolumeLeveller(const dsVolumeLeveller_t volLeveller); @@ -164,7 +177,7 @@ class AudioOutputPort : public Enumerable { void setGraphicEqualizerMode(const int mode); void setMS12AudioProfile(std::string profile); - void setStereoMode(const int mode, const bool toPersist = true); + void setStereoMode(const int mode, const bool toPersist = true) {} void setStereoAuto(const bool autoMode, const bool toPersist = true); void setEncoding(const std::string & encoding); @@ -173,7 +186,7 @@ class AudioOutputPort : public Enumerable { void setSAD(std::vector sad_list); void enableARC(dsAudioARCTypes_t type, bool enable); void enableMS12Config(const dsMS12FEATURE_t feature,const bool enable){} - dsError_t enableLEConfig(const bool enable); + dsError_t enableLEConfig(const bool enable) { return dsERR_NONE; }; bool GetLEConfig(); void setAudioDelay(const uint32_t audioDelayMs); void setAudioDelayOffset(const uint32_t audioDelayOffsetMs); @@ -189,11 +202,11 @@ class AudioOutputPort : public Enumerable { void setSecondaryLanguage(const std::string sLang); void getSecondaryLanguage(std::string &sLang); - void setDB(const float db); + void setDB(const float db) {} void setGain(const float newGain); - void setLevel(const float level); - void setLoopThru(const bool loopThru); - void setMuted(const bool mute); + void setLevel(const float level) {} + void setLoopThru(const bool loopThru) {} + void setMuted(const bool mute) {} void setAudioDucking(dsAudioDuckingAction_t action, dsAudioDuckingType_t, const unsigned char level); void getAudioCapabilities(int *capabilities); void getMS12Capabilities(int *capabilities); diff --git a/src/unittest/stubs/ds/audioStereoMode.hpp b/src/unittest/stubs/ds/audioStereoMode.hpp index 8b7538c32..89852cfac 100644 --- a/src/unittest/stubs/ds/audioStereoMode.hpp +++ b/src/unittest/stubs/ds/audioStereoMode.hpp @@ -53,7 +53,7 @@ class AudioStereoMode : public DSConstant { public: static const int kMono; //!< Indicates audio mode of type mono. - static const int kStereo; //!< Indicates audio mode of type stereo. + static const int kStereo = 1; //!< Indicates audio mode of type stereo. static const int kSurround; //!< Indicates audio mode of type surround. static const int kPassThru; //!< Indicates audio mode of type pass through. static const int kDD; //!< Indicates audio mode of type dolby digital. @@ -63,8 +63,8 @@ class AudioStereoMode : public DSConstant { static const AudioStereoMode & getInstance(int id); static const AudioStereoMode & getInstance(const std::string &name); - AudioStereoMode(int id); - virtual ~AudioStereoMode(); + AudioStereoMode(int id) {} + virtual ~AudioStereoMode() {} }; diff --git a/src/unittest/stubs/ds/frameRate.hpp b/src/unittest/stubs/ds/frameRate.hpp index a8d4b150a..bfc3e2805 100644 --- a/src/unittest/stubs/ds/frameRate.hpp +++ b/src/unittest/stubs/ds/frameRate.hpp @@ -53,7 +53,7 @@ class FrameRate : public DSConstant { static const int k24; //!< Indicates video frame rate of 24 fps. static const int k25; //!< Indicates video frame rate of 25 fps. static const int k30; //!< Indicates video frame rate of 30 fps. - static const int k60; //!< Indicates video frame rate of 60 fps. + static constexpr int k60 = 60; //!< Indicates video frame rate of 60 fps. static const int k23dot98; //!< Indicates video frame rate of 23.98 fps. static const int k29dot97; //!< Indicates video frame rate of 29.97 fps. static const int k50; //!< Indicates video frame rate of 50 fps. @@ -63,9 +63,9 @@ class FrameRate : public DSConstant { static const FrameRate & getInstance(int id); static const FrameRate & getInstance(const std::string &name); - FrameRate(float value); - FrameRate(int id); - virtual ~FrameRate(); + FrameRate(float value) {} + FrameRate(int id) {} + virtual ~FrameRate() {} }; } diff --git a/src/unittest/stubs/ds/host.hpp b/src/unittest/stubs/ds/host.hpp index a18c55f71..af0d3a5cf 100644 --- a/src/unittest/stubs/ds/host.hpp +++ b/src/unittest/stubs/ds/host.hpp @@ -63,8 +63,11 @@ class Host { static const int kPowerOff; static const int kPowerStandby; - bool setPowerMode(int mode); - int getPowerMode(); + bool setPowerMode(int mode) + { + return true; + } + int getPowerMode() { return 10; } SleepMode getPreferredSleepMode(); int setPreferredSleepMode(const SleepMode); List getAvailableSleepModes(); @@ -77,13 +80,23 @@ class Host { List getVideoOutputPorts(); List getAudioOutputPorts(){}; - List getVideoDevices(); - VideoOutputPort &getVideoOutputPort(const std::string &name); + List getVideoDevices() + { + List devices; + devices.push_back(VideoDevice(1)); + devices.push_back(VideoDevice(2)); + return devices; + } + VideoOutputPort &getVideoOutputPort(const std::string &name) + { + static VideoOutputPort vPort(name); + return vPort; + } VideoOutputPort &getVideoOutputPort(int id); AudioOutputPort &getAudioOutputPort(const std::string &name){}; AudioOutputPort &getAudioOutputPort(int id){}; void notifyPowerChange(const int mode); - float getCPUTemperature(); + float getCPUTemperature() { return 42.5f; }; uint32_t getVersion(void); void setVersion(uint32_t versionNumber); void getHostEDID(std::vector &edid) const; @@ -99,7 +112,7 @@ class Host { void setSecondaryLanguage(const std::string sLang); void getSecondaryLanguage(std::string &sLang); bool isHDMIOutPortPresent(); - std::string getDefaultVideoPortName(); + std::string getDefaultVideoPortName() { return "port"; } std::string getDefaultAudioPortName(); void getCurrentAudioFormat(dsAudioFormat_t &audioFormat); void getMS12ConfigDetails(std::string &configType); diff --git a/src/unittest/stubs/ds/libprocps.cpp b/src/unittest/stubs/ds/libprocps.cpp new file mode 100644 index 000000000..a25577f69 --- /dev/null +++ b/src/unittest/stubs/ds/libprocps.cpp @@ -0,0 +1,19 @@ +extern "C" { +#include +} + +static int call_count = 0; + +PROCTAB* openproc(int flags, ...) { + // Your stub implementation here + return nullptr; +} + +void closeproc(PROCTAB* pt) { + // Your stub implementation here +} + +proc_t* readproc(PROCTAB* pt, proc_t* buffer) { + // Your stub implementation here + return nullptr; +} diff --git a/src/unittest/stubs/ds/manager.hpp b/src/unittest/stubs/ds/manager.hpp index 4513024ae..c715a8836 100644 --- a/src/unittest/stubs/ds/manager.hpp +++ b/src/unittest/stubs/ds/manager.hpp @@ -166,8 +166,8 @@ class Manager { Manager(); virtual ~Manager(); public: - static void Initialize(); - static void DeInitialize(); + static void Initialize() {} + static void DeInitialize() {} static int IsInitialized; //!< Indicates the application has initialized with devicettings modules. }; diff --git a/src/unittest/stubs/ds/pixelResolution.hpp b/src/unittest/stubs/ds/pixelResolution.hpp index a3b6dbb94..938b242da 100644 --- a/src/unittest/stubs/ds/pixelResolution.hpp +++ b/src/unittest/stubs/ds/pixelResolution.hpp @@ -65,8 +65,8 @@ class PixelResolution : public DSConstant { static const PixelResolution & getInstance(int id); static const PixelResolution & getInstance(const std::string &name); - PixelResolution(int id); - virtual ~PixelResolution(); + PixelResolution(int id) {} + virtual ~PixelResolution() {} }; } diff --git a/src/unittest/stubs/ds/videoDFC.hpp b/src/unittest/stubs/ds/videoDFC.hpp index 600aa87b5..044c933b1 100644 --- a/src/unittest/stubs/ds/videoDFC.hpp +++ b/src/unittest/stubs/ds/videoDFC.hpp @@ -76,8 +76,8 @@ class VideoDFC : public DSConstant { static const VideoDFC & getInstance(int id); static const VideoDFC & getInstance(const std::string &name); - VideoDFC(int id); - virtual ~VideoDFC(); + VideoDFC(int id) {} + virtual ~VideoDFC() {} }; } diff --git a/src/unittest/stubs/ds/videoDevice.hpp b/src/unittest/stubs/ds/videoDevice.hpp index 61ec375df..0468c3e90 100644 --- a/src/unittest/stubs/ds/videoDevice.hpp +++ b/src/unittest/stubs/ds/videoDevice.hpp @@ -60,21 +60,42 @@ class VideoDevice : public DSConstant { static const char * kPropertyDFC; public: - static VideoDevice & getInstance(int id); - static VideoDevice & getInstance(const std::string &name); - - VideoDevice(int id); + static VideoDevice & getInstance(int id) + { + static VideoDevice instance(id); + return instance; + } + static VideoDevice & getInstance(const std::string &name) + { + static VideoDevice instance(0); + return instance; + } + + VideoDevice(int id) {} void setDFC(const std::string & name); void setDFC(int id); void setPlatformDFC(); - const VideoDFC & getDFC(); + const VideoDFC & getDFC() + { + static VideoDFC vDFC(0); + return vDFC; + } const List getSupportedDFCs() const; void addDFC(const VideoDFC &dfc); - virtual ~VideoDevice(); + virtual ~VideoDevice() {} void getHDRCapabilities(int *capabilities); - void getSettopSupportedResolutions(std::list& stbSupportedResoltuions); - unsigned int getSupportedVideoCodingFormats() const; - dsVideoCodecInfo_t getVideoCodecInfo(dsVideoCodingFormat_t format) const; + void getSettopSupportedResolutions(std::list& stbSupportedResoltuions) + { + stbSupportedResoltuions.push_back("1920x1080"); + stbSupportedResoltuions.push_back("1280x720"); + } + unsigned int getSupportedVideoCodingFormats() const { return 0x1F; } + dsVideoCodecInfo_t getVideoCodecInfo(dsVideoCodingFormat_t format) const + { + dsVideoCodecInfo_t codecInfo = {}; + codecInfo.num_entries = 2; + return codecInfo; + } int forceDisableHDRSupport(bool disable); int getFRFMode(int *frfmode) const; int setFRFMode(int frfmode) const; diff --git a/src/unittest/stubs/ds/videoOutputPort.hpp b/src/unittest/stubs/ds/videoOutputPort.hpp index c1b78be7c..0986d0e7c 100644 --- a/src/unittest/stubs/ds/videoOutputPort.hpp +++ b/src/unittest/stubs/ds/videoOutputPort.hpp @@ -38,6 +38,9 @@ #include #include "dsTypes.h" +#include "videoResolution.hpp" +#include "frameRate.hpp" +#include "videoOutputPortType.hpp" /** * @file videoOutputPort.hpp @@ -105,7 +108,7 @@ class VideoOutputPort : public Enumerable { Display() :_handle(0), _productCode(0), _serialNumber(0), _manufacturerYear(0), _manufacturerWeek(0),_aspectRatio(0),_hdmiDeviceType(true), _isSurroundCapable(false), _isDeviceRepeater(false), _physicalAddressA(1),_physicalAddressB(0),_physicalAddressC(0),_physicalAddressD(0){}; Display(VideoOutputPort &vPort); - virtual ~Display(); + virtual ~Display() {} /** @@ -154,7 +157,7 @@ class VideoOutputPort : public Enumerable { */ int getConnectedDeviceType() const {return _hdmiDeviceType;}; bool isConnectedDeviceRepeater() const {return _isDeviceRepeater;}; - void getEDIDBytes(std::vector &edid) const; + void getEDIDBytes(std::vector &edid) const { edid.clear(); } /** * @fn int hasSurround() const @@ -198,12 +201,20 @@ class VideoOutputPort : public Enumerable { physicalAddressC = _physicalAddressC;physicalAddressD = _physicalAddressD;}; }; - static VideoOutputPort & getInstance(int id); + static VideoOutputPort & getInstance(int id) + { + static VideoOutputPort port(0, 0, 0, 0, "1080p60"); + return port; + } static VideoOutputPort & getInstance(const std::string &name); VideoOutputPort(const int type, const int index, const int id, int audioPortId, const std::string &resolution); - virtual ~VideoOutputPort(); + virtual ~VideoOutputPort() {} - const VideoOutputPortType &getType() const; + const VideoOutputPortType &getType() const + { + static VideoOutputPortType portType(0); + return portType; + } /** @@ -234,13 +245,25 @@ class VideoOutputPort : public Enumerable { int getIndex() const {return _index; }; AudioOutputPort &getAudioOutputPort(); - const VideoResolution &getResolution() ; - const VideoResolution &getDefaultResolution() const; - - const VideoOutputPort::Display &getDisplay(); - bool isDisplayConnected() const; + const VideoResolution &getResolution() + { + static VideoResolution videoRes(0, "1080p60", 1, 1, 0, FrameRate::k60, false, true); + return videoRes; + } + const VideoResolution &getDefaultResolution() const + { + static VideoResolution videoRes(0, "1080p60", 1, 1, 0, 5, false, true); + return videoRes; + } + + const VideoOutputPort::Display &getDisplay() + { + static Display display; + return display; + } + bool isDisplayConnected() const { return true; } bool isContentProtected() const; - bool isEnabled() const; + bool isEnabled() const { return true; } bool isActive() const; bool isDynamicResolutionSupported() const; @@ -253,11 +276,11 @@ class VideoOutputPort : public Enumerable { * @return None. */ void setAudioPort(int id) { _aPortId = id; }; - void setResolution(const std::string &resolution, bool persist = true, bool isIgnoreEdid=false); + void setResolution(const std::string &resolution, bool persist = true, bool isIgnoreEdid=false) {} void setDisplayConnected(const bool connected); - void enable(); - void disable(); - int getHDCPStatus(); + void enable() {} + void disable() {} + int getHDCPStatus() { return 1; } int getHDCPProtocol(); int getHDCPReceiverProtocol(); int getHDCPCurrentProtocol(); @@ -280,6 +303,7 @@ class VideoOutputPort : public Enumerable { const unsigned int getPreferredColorDepth(bool persist = true) ; void setPreferredColorDepth(const unsigned int colordepth, bool persist = true); void getColorDepthCapabilities (unsigned int *capabilities) const; + VideoOutputPort(const std::string& name) {} private: Display _display; diff --git a/src/unittest/stubs/ds/videoOutputPortType.hpp b/src/unittest/stubs/ds/videoOutputPortType.hpp index 066e61f98..00cc2a68f 100644 --- a/src/unittest/stubs/ds/videoOutputPortType.hpp +++ b/src/unittest/stubs/ds/videoOutputPortType.hpp @@ -50,6 +50,7 @@ */ namespace device { +class VideoOutputPort; /** * @class VideoOutputPortType @@ -83,15 +84,20 @@ class VideoOutputPortType : public DSConstant { static VideoOutputPortType & getInstance(const std::string &name); - VideoOutputPortType(const int id); - virtual ~VideoOutputPortType(); + VideoOutputPortType(const int id) {} + virtual ~VideoOutputPortType() {} int getTypeId() const; bool isDTCPSupported() const; bool isHDCPSupported() const; bool isDynamicResolutionsSupported() const; int getRestrictedResolution() const ; - const List getSupportedResolutions() const; + const List getSupportedResolutions() const + { + List supportedResolutions; + supportedResolutions.push_back(VideoResolution(0, "1080p60", 1, 1, 0, 5, false, true)); + return supportedResolutions; + } const VideoResolution & getOutputResolution(const VideoResolution &inputResolution) const; const List getPorts() const; diff --git a/src/unittest/stubs/ds/videoResolution.hpp b/src/unittest/stubs/ds/videoResolution.hpp index a6bb6c2d0..a50cd636f 100644 --- a/src/unittest/stubs/ds/videoResolution.hpp +++ b/src/unittest/stubs/ds/videoResolution.hpp @@ -67,19 +67,32 @@ class VideoResolution : public DSConstant { public: - static const VideoResolution & getInstance(int id); + static const VideoResolution & getInstance(int id) {} static const VideoResolution & getInstance(const std::string &name, bool isIgnoreEdid=false); VideoResolution(const int id, const std::string &name, int resolutionId, int ratioid, int ssModeId, - int frameRateId, bool interlacedId, bool enabled = true); - virtual ~VideoResolution(); - const PixelResolution & getPixelResolution() const; + int frameRateId, bool interlacedId, bool enabled = true) + { + } + virtual ~VideoResolution() {} + const PixelResolution & getPixelResolution() const + { + static PixelResolution pixelRes(0); + return pixelRes; + } const AspectRatio & getAspectRatio() const; const StereoScopicMode & getStereoscopicMode()const; - const FrameRate & getFrameRate() const; - bool isInterlaced() const; + const FrameRate & getFrameRate() const + { + static FrameRate frameRate(FrameRate::k60); + return frameRate; + } + bool isInterlaced() const + { + return true; + } bool isEnabled() const; }; diff --git a/src/unittest/stubs/file_writer.cpp b/src/unittest/stubs/file_writer.cpp new file mode 100644 index 000000000..7f064b656 --- /dev/null +++ b/src/unittest/stubs/file_writer.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include "file_writer.h" + +void writeToTr181storeFile(const std::string& key, const std::string& value, const std::string& filePath, ValueFormat format) { + // Check if the file exists and is openable in read mode + std::ifstream fileStream(filePath); + bool found = false; + std::string line; + std::vector lines; + + std::string formattedLine = (format == Quoted) + ? key + "=\"" + value + "\"" + : key + "=" + value; + + if (fileStream.is_open()) { + while (getline(fileStream, line)) { + // Check if the current line contains the key + if (line.find(key) != std::string::npos && line.substr(0, key.length()) == key) { + // Replace the line with the new key-value pair + line = formattedLine; + found = true; + } + lines.push_back(line); + } + fileStream.close(); + } else { + std::cout << "File does not exist or cannot be opened for reading. It will be created." << std::endl; + } + + // If the key was not found in an existing file or the file did not exist, add it to the vector + if (!found) { + lines.push_back(formattedLine); + } + + // Open the file in write mode to overwrite old content or create new file + std::ofstream outFileStream(filePath); + if (outFileStream.is_open()) { + for (const auto& outputLine : lines) { + outFileStream << outputLine << std::endl; + } + outFileStream.close(); + std::cout << "Configuration updated successfully." << std::endl; + } else { + std::cout << "Error opening file for writing." << std::endl; + } +} + + +void write_on_file(const std::string& filePath, const std::string& data) +{ + std::ofstream outfile(filePath, std::ios::app); + if (outfile.is_open()) { + std::cout << "File Open" << std::endl; + outfile << data ; + std::cout << "Writing in file" << std::endl; + outfile.close(); + std::cout << "File written successfully." << std::endl; + } else { + std::cerr << "Unable to open file." << std::endl ; + } + +} diff --git a/src/unittest/stubs/file_writer.h b/src/unittest/stubs/file_writer.h new file mode 100644 index 000000000..b313e1193 --- /dev/null +++ b/src/unittest/stubs/file_writer.h @@ -0,0 +1,22 @@ +#ifndef FILE_WRITER_H +#define FILE_WRITER_H + +#include + +enum ValueFormat { + Plain, // key=value + Quoted // key="value" +}; + +/** + * @brief Writes or updates a key="value" pair in a flat TR-181-style config file. + * + * @param key The TR-181 parameter name (e.g., "Device.DeviceInfo...") + * @param value The string value to be assigned (e.g., "true") + * @param filePath Path to the config file to read/update/create + */ +void writeToTr181storeFile(const std::string& key, const std::string& value, const std::string& filePath, ValueFormat format); + +void write_on_file(const std::string& filePath, const std::string& data); + +#endif // FILE_WRITER_H diff --git a/src/unittest/stubs/libparodus.h b/src/unittest/stubs/libparodus.h new file mode 100644 index 000000000..80ab3ab46 --- /dev/null +++ b/src/unittest/stubs/libparodus.h @@ -0,0 +1,212 @@ +/** + * Copyright 2016 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef _LIBPARODUS_H +#define _LIBPARODUS_H + +#include "wrp-c.h" +#include "libparodus_log.h" + +#ifdef __cplusplus +extern "C" { /* open extern "C" */ +#endif + +/** + * This module is linked with the client, and provides connectivity + * to the parodus service. + */ + +typedef struct { + const char *service_name; + bool receive; + int keepalive_timeout_secs; + const char *parodus_url; + const char *client_url; + unsigned test_flags; // always 0 except when testing +} libpd_cfg_t; + +typedef void *libpd_instance_t; + + +/** + * @brief libparodus error rtn codes + * + */ +typedef enum { + /** + * @brief Error on libparodus_init + * could not create new instance + */ + LIBPD_ERROR_INIT_INST = -101, + /** + * @brief Error on libparodus_init + * invalid cfg parameter + */ + LIBPD_ERROR_INIT_CFG = -102, + /** + * @brief Error on libparodus_init + * error connecting + */ + LIBPD_ERROR_INIT_CONNECT = -103, + /** + * @brief Error on libparodus_close_receiver + * null instance given + */ + LIBPD_ERROR_CLOSE_RCV_NULL_INST = -301, + /** + * @brief Error on libparodus_close_receiver + * run state error + */ + LIBPD_ERROR_CLOSE_RCV_STATE = -302, + /** + * @brief Error on libparodus_close_receiver + * not configured for receive + */ + LIBPD_ERROR_CLOSE_RCV_CFG = -303, + /** + * @brief Error on libparodus_close_receiver + * queue send error, timed out + */ + LIBPD_ERROR_CLOSE_RCV_TIMEDOUT = -304, + /** + * @brief Error on libparodus_close_receiver + * unable to send close recevier message + */ + LIBPD_ERROR_CLOSE_RCV_SEND = -305, + /** + * @brief Error on libparodus_close_receiver + * thread limit exceeded + */ + LIBPD_ERROR_CLOSE_RCV_THR_LIMIT = -306, + /** + * @brief Error on libparodus_send + * null instance given + */ + LIBPD_ERROR_SEND_NULL_INST = -401, + /** + * @brief Error on libparodus_send + * run state error + */ + LIBPD_ERROR_SEND_STATE = -402, + /** + * @brief Error on libparodus_send + * invalid WRP message + */ + LIBPD_ERROR_SEND_WRP_MSG = -403, + /** + * @brief Error on libparodus_send + * socket send error + */ + LIBPD_ERROR_SEND_SOCKET = -404, + /** + * @brief Error on libparodus_send + * thread limit exceeded + */ + LIBPD_ERROR_SEND_THR_LIMIT = -405 +} libpd_error_t; + +/** + * Initialize the parodus wrp interface + * + * @param instance pointer to receive instance object that must be provided + * to all subsequent API calls. + * @param cfg configuration information: service_name must be provided, + * @return 0 on success, else: + * LIBPD_ERROR_INIT_INST = -101, could not create new instance + * LIBPD_ERROR_INIT_CFG = -102, invalid config parameter + * LIBPD_ERROR_INIT_CONNECT = -103, error connecting + * LIBPD_ERROR_INIT_RCV_THREAD = -104, error creating wrp receiver thread + * LIBPD_ERROR_INIT_QUEUE = -105, error creating wrp msg receive queue + * LIBPD_ERROR_INIT_REGISTER = -106, error sending registration msg + * + * @note libparodus_shutdown must be called even if there is an error + * on libparodus_init + */ +int libparodus_init (libpd_instance_t *instance, libpd_cfg_t *libpd_cfg); + +/** + * Receives the next message in the queue that was sent to this service, waiting + * the prescribed number of milliseconds before returning. + * + * @note msg will be set to NULL if no message is present during the time + * allotted. + * + * @param instance instance object + * @param msg the pointer to receive the next msg struct + * @param ms the number of milliseconds to wait for the next message + * + * @return 0 on success, 2 if closed msg received, 1 if timed out, else: + * LIBPD_ERROR_RCV_NULL_INST = -201, null instance given + * LIBPD_ERROR_RCV_STATE = -202, run state error, not running + * LIBPD_ERROR_RCV_CFG = -203, not configured for receive + * LIBPD_ERROR_RCV_RCV = -204, receive error + * + * @note don't free the msg when return is 2. + */ +int libparodus_receive (libpd_instance_t instance, wrp_msg_t **msg, uint32_t ms); + +/** + * Sends a close message to the receiver + * + * @param instance instance object + * @return 0 on success, else: + * LIBPD_ERROR_CLOSE_RCV_NULL_INST = -301, null instance given + * LIBPD_ERROR_CLOSE_RCV_STATE = -302, run state error, not running + * LIBPD_ERROR_CLOSE_RCV_CFG = -303, not configured for receive + * LIBPD_ERROR_CLOSE_RCV_TIMEDOUT = -304, timed out on queue send + * LIBPD_ERROR_CLOSE_RCV_SEND = -305, unable to send close receiver msg + */ +int libparodus_close_receiver (libpd_instance_t instance); + +/** + * Shut down the parodus wrp interface + * + * @param instance instance object + * @return always 0 +*/ + +int libparodus_shutdown (libpd_instance_t *instance); + + +/** + * Send a wrp message to the parodus service + * + * @param instance instance object + * @param msg wrp message to send + * + * @return 0 on success, else: + * LIBPD_ERROR_SEND_NULL_INST = -501, null instance given + * LIBPD_ERROR_SEND_STATE = -502, run state error, not running + * LIBPD_ERROR_SEND_WRP_MSG = -503, invalid wrp message + * LIBPD_ERROR_SEND_SOCKET = -504, socket send error + */ +int libparodus_send (libpd_instance_t instance, wrp_msg_t *msg); + +/** + * Return the string value of a libparodus error code + * + * @param err libparodus error code + * + * @return string value of the specified error code + */ +const char *libparodus_strerror (libpd_error_t err); + +#ifdef __cplusplus +} /* close extern "C" */ +#endif + +#endif diff --git a/src/unittest/stubs/libparodus_log.h b/src/unittest/stubs/libparodus_log.h new file mode 100644 index 000000000..a2e427c85 --- /dev/null +++ b/src/unittest/stubs/libparodus_log.h @@ -0,0 +1,84 @@ +/** + * Copyright 2016 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef _LIBPARODUS_LOG_H +#define _LIBPARODUS_LOG_H + +#include + +#define LEVEL_ERROR 0 +#define LEVEL_INFO 1 +#define LEVEL_DEBUG 2 + +// if TEST_ENVIRONMENT is not defined, then the macros libpd_log and libpd_log_err +// generate nothing +//#define TEST_ENVIRONMENT 1 + +#ifndef TEST_ENVIRONMENT +#define libpd_log(level,msg) +#define libpd_log_err(level,errcode,msg) +#else +// TEST_ENVIRONMENT defined + +#include +#include + +// When TEST_ENVIRONMENT == 1, printf is used. +// If TEST_ENVIRONMENT > 1, then you need to provide +// external functions 'CheckLevel' and 'Printf' + +#if TEST_ENVIRONMENT==1 +#define Printf printf +#define output_level(level) \ + if ((level) == LEVEL_ERROR) \ + Printf ("Error: "); \ + else if ((level) == LEVEL_INFO) \ + Printf ("Info: "); \ + else \ + Printf ("Debug: "); + +#define libpd_log(level,msg) \ + do { \ + output_level (level); \ + Printf msg; \ + } while (false) + +#else +// TEST_ENVIRONMENT > 1 + + extern bool CheckLevel (int level); + extern int Printf (const char *format, ...); + +#define libpd_log(level,msg) if (CheckLevel (level)) Printf msg + +#endif +// Example: libpd_log (LEVEL_ERROR, ("Unable to allocate new instance\n")); +// notice you need an extra set of parentheses + +#define libpd_log_err(level,errcode,msg) \ + libpd_log (level, msg); \ + do { \ + char errbuf[100]; \ + Printf (" : %s\n", strerror_r (errcode, errbuf, 100)); \ + } while (false) + +// Example: libpd_log_err (LEVEL_ERROR, errno, ("Unable to bind to receive_socket %s\n", rcv_url)); +// notice you need an extra set of parentheses + +#endif + + +#endif diff --git a/src/unittest/stubs/paramMgr.c b/src/unittest/stubs/paramMgr.c new file mode 100644 index 000000000..44a568f61 --- /dev/null +++ b/src/unittest/stubs/paramMgr.c @@ -0,0 +1,4 @@ +#include "paramMgr.h" + +GHashTable* paramMgrhash = NULL; // Definition +T_ARGLIST argList = {0}; diff --git a/src/unittest/stubs/paramMgr.h b/src/unittest/stubs/paramMgr.h new file mode 100644 index 000000000..1d70b18a0 --- /dev/null +++ b/src/unittest/stubs/paramMgr.h @@ -0,0 +1,18 @@ +// paramMgr.h +#ifndef PARAM_MGR_H +#define PARAM_MGR_H + +#include + +extern GHashTable* paramMgrhash; // Declaration + +typedef struct argsList { + char logFileName[64]; + char confFile[100]; + int httpPort; +#ifndef NEW_HTTP_SERVER_DISABLE + int httpServerPort; //new HTTP Server Port for JSON Requests +#endif +} T_ARGLIST; + +#endif diff --git a/src/unittest/stubs/power_controller.h b/src/unittest/stubs/power_controller.h new file mode 100644 index 000000000..e147e53a6 --- /dev/null +++ b/src/unittest/stubs/power_controller.h @@ -0,0 +1,372 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2025 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef POWERMANAGER_CLIENT_H +#define POWERMANAGER_CLIENT_H + +#include +#include + +#undef EXTERNAL +#if defined(WIN32) || defined(_WINDOWS) || defined (__CYGWIN__) || defined(_WIN64) +#ifdef DEVICEINFO_EXPORTS +#define EXTERNAL __declspec(dllexport) +#else +#define EXTERNAL __declspec(dllimport) +#pragma comment(lib, "deviceinfo.lib") +#endif +#else +#define EXTERNAL __attribute__((visibility("default"))) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum PowerController_PowerState { + POWER_STATE_UNKNOWN = 0 /* UNKNOWN */, + POWER_STATE_OFF = 1 /* OFF */, + POWER_STATE_STANDBY = 2 /* STANDBY */, + POWER_STATE_ON = 3 /* ON */, + POWER_STATE_STANDBY_LIGHT_SLEEP = 4 /* LIGHT_SLEEP */, + POWER_STATE_STANDBY_DEEP_SLEEP = 5 /* DEEP_SLEEP */ +} PowerController_PowerState_t; + +typedef enum PowerController_ThermalTemperature { + THERMAL_TEMPERATURE_UNKNOWN = 0 /* UNKNOWN Thermal Temperature */, + THERMAL_TEMPERATURE_NORMAL = 1 /* Normal Thermal Temperature */, + THERMAL_TEMPERATURE_HIGH = 2 /* High Thermal Temperature */, + THERMAL_TEMPERATURE_CRITICAL = 4 /* Critial Thermal Temperature */ +} PowerController_ThermalTemperature_t; + +typedef enum PowerController_WakeupSrcType { + WAKEUP_SRC_UNKNOWN = 0 /* UNKNOWN */, + WAKEUP_SRC_VOICE = 1 /* VOICE */, + WAKEUP_SRC_PRESENCEDETECTED = 2 /* PRESENCEDETECTED */, + WAKEUP_SRC_BLUETOOTH = 3 /* BLUETOOTH */, + WAKEUP_SRC_WIFI = 4 /* WIFI */, + WAKEUP_SRC_IR = 5 /* IR */, + WAKEUP_SRC_POWERKEY = 6 /* POWERKEY */, + WAKEUP_SRC_TIMER = 7 /* TIMER */, + WAKEUP_SRC_CEC = 8 /* CEC */, + WAKEUP_SRC_LAN = 9 /* LAN */, + WAKEUP_SRC_RF4CE = 10 /* RF4CE */ +} PowerController_WakeupSrcType_t; + +typedef enum PowerController_WakeupReason { + WAKEUP_REASON_UNKNOWN = 0 /* UNKNOWN */, + WAKEUP_REASON_IR = 1 /* IR */, + WAKEUP_REASON_BLUETOOTH = 2 /* BLUETOOTH */, + WAKEUP_REASON_RF4CE = 3 /* RF4CE */, + WAKEUP_REASON_GPIO = 4 /* GPIO */, + WAKEUP_REASON_LAN = 5 /* LAN */, + WAKEUP_REASON_WIFI = 6 /* WIFI */, + WAKEUP_REASON_TIMER = 7 /* TIMER */, + WAKEUP_REASON_FRONTPANEL = 8 /* FRONTPANEL */, + WAKEUP_REASON_WATCHDOG = 9 /* WATCHDOG */, + WAKEUP_REASON_SOFTWARERESET = 10 /* SOFTWARERESET */, + WAKEUP_REASON_THERMALRESET = 11 /* THERMALRESET */, + WAKEUP_REASON_WARMRESET = 12 /* WARMRESET */, + WAKEUP_REASON_COLDBOOT = 13 /* COLDBOOT */, + WAKEUP_REASON_STRAUTHFAIL = 14 /* STR_AUTH_FAIL */, + WAKEUP_REASON_CEC = 15 /* CEC */, + WAKEUP_REASON_PRESENCE = 16 /* PRESENCE */, + WAKEUP_REASON_VOICE = 17 /* VOICE */ +} PowerController_WakeupReason_t; + +typedef enum PowerController_SystemMode { + SYSTEM_MODE_UNKNOWN = 0 /* UNKNOWN */, + SYSTEM_MODE_NORMAL = 1 /* NORMAL */, + SYSTEM_MODE_EAS = 2 /* EAS */, + SYSTEM_MODE_WAREHOUSE = 3 /* WAREHOUSE */ +} PowerController_SystemMode_t; + +#define POWER_CONTROLLER_ERROR_NONE 0 +#define POWER_CONTROLLER_ERROR_GENERAL 1 +#define POWER_CONTROLLER_ERROR_UNAVAILABLE 2 + +/** + * @brief Initializes the Power Controller. + * + * This function creates an instance of the PowerManager plugin client interface and increments the client instance count. + * + * @details + * - If the Power Controller instance does not already exist, it will be created. + * - The instance count is incremented each time this function is called. + * - After Init, & before making any PowerController request client needs to ensure + * - Power Manager plugin is activated and operational via `PowerController_IsOperational`. + * - If not operational, clients can use this Connect API to establish COM-RPC connection with the Power Manager plugin. + * - If there us any failure in Connect all PowerController requests will fail with `POWER_CONTROLLER_ERROR_UNAVAILABLE` (Except for callback register / unregister APIs). + * + * @see PowerController_Term + */ +EXTERNAL void PowerController_Init(); + +/** + * @brief PowerController attempts to connect to the Power Manager plugin. + * + * This function connects to the Power Manager plugin. + * + * @details + * - This function is used to connect to the Power Manager plugin. + * - Before making any PowerController request client needs to ensure + * - Power Manager plugin is activated and operational via `PowerController_IsOperational`. + * - If not operational, clients can use this Connect API to establish COM-RPC connection with the Power Manager plugin. + * - If there us any failure in Connect all PowerController requests will fail with `POWER_CONTROLLER_ERROR_UNAVAILABLE` (Except for callback register / unregister APIs). + * - In case of failure this API should be called again with brief delay. + * + * @return `POWER_CONTROLLER_ERROR_NONE` on success. + * @return `POWER_CONTROLLER_ERROR_UNAVAILABLE` if Thunder RPC server is not running / error establishing RPC communication channel. + * @return `POWER_CONTROLLER_ERROR_NOT_EXIST` if the PowerManager plugin is not activated yet. + */ +EXTERNAL uint32_t PowerController_Connect(); + +/** + * @brief Terminates the Power Controller. + * + * This function decrements client instance count attempts to delete Power Controller instance + * + * @details + * - If the controller reference count is greater than one, this function only decrements the count. + * - When the reference count reaches zero, the controller instance is destroyed, and all associated resources are released (PowerManager plugin client instance). + * - Ensure that this function is called once for every call to `PowerController_Init`. + * + * @see PowerController_Init + */ +EXTERNAL void PowerController_Term(); + +/** + * @brief Checks if the Power Manager plugin is active & operational + * + * This function determines whether the Power Manager interface is operational and ready to handle requests. + * It can be used to verify the availability of the Power Manager client before initiating operations that depend on it. + * + * IMPORTANT - This is the first function that should be called after `PowerController_Init`. + * + * @return `true` if the Power Manager interface is active and operational, otherwise `false`. + * + * @details + * - Use this function to confirm the operational status of the Power Manager plugin. + * - Calling this function is NOT MANDATORY but optional + * - Clients can register for notifications about state changes using `PowerController_RegisterOperationalStateChangeCallback`. + * - If the Power Manager interface is not active, subsequent Power Manager operations will fail with the error `POWER_CONTROLLER_ERROR_UNAVAILABLE`. + * - Therefore in failure cases, clients can use `PowerController_Connect` to establish COM-RPC connection with the Power Manager plugin. + * + * @see PowerController_RegisterOperationalStateChangeCallback + */ +EXTERNAL bool PowerController_IsOperational(); + +/** Gets the Power State.*/ +// @text getPowerState +// @brief Get Power State +// @param powerState: Get current power state +EXTERNAL uint32_t PowerController_GetPowerState(PowerController_PowerState_t* currentState /* @out */, PowerController_PowerState_t* previousState /* @out */); + +/** Sets Power State . */ +// @text setPowerState +// @brief Set Power State +// @param keyCode: NA for most platfroms, to be depricated +// @param powerState: Set power to this state +// @param reason: null terminated string stating reason for for state change +EXTERNAL uint32_t PowerController_SetPowerState(const int keyCode /* @in */, const PowerController_PowerState_t powerstate /* @in */, const char* reason /* @in */); + +/** Gets the current Thermal state.*/ +// @text getThermalState +// @brief Get Current Thermal State (temperature) +// @param currentTemperature: current temperature +EXTERNAL uint32_t PowerController_GetThermalState(float* currentTemperature /* @out */); + +/** Sets the Temperature Thresholds.*/ +// @text setTemperatureThresholds +// @brief Set Temperature Thresholds +// @param high: high threshold +// @param critical : critical threshold +EXTERNAL uint32_t PowerController_SetTemperatureThresholds(float high /* @in */, float critical /* @in */); + +/** Gets the current Temperature Thresholds.*/ +// @text getTemperatureThresholds +// @brief Get Temperature Thresholds +// @param high: high threshold +// @param critical : critical threshold +EXTERNAL uint32_t PowerController_GetTemperatureThresholds(float* high /* @out */, float* critical /* @out */); + +/** Sets the current Temperature Grace interval.*/ +// @property +// @text PowerController_SetOvertempGraceInterval +// @brief Set Temperature Thresholds +// @param graceInterval: interval in secs? +EXTERNAL uint32_t PowerController_SetOvertempGraceInterval(const int graceInterval /* @in */); + +/** Gets the grace interval for over-temperature.*/ +// @property +// @text PowerController_GetOvertempGraceInterval +// @brief Get Temperature Grace interval +// @param graceInterval: interval in secs? +EXTERNAL uint32_t PowerController_GetOvertempGraceInterval(int* graceInterval /* @out */); + +/** Set Deep Sleep Timer for later wakeup */ +// @property +// @text setDeepSleepTimer +// @brief Set Deep sleep timer for timeOut period +// @param timeOut: deep sleep timeout +EXTERNAL uint32_t PowerController_SetDeepSleepTimer(const int timeOut /* @in */); + +/** Get Last Wakeup reason */ +// @property +// @text getLastWakeupReason +// @brief Get Last Wake up reason +// @param wakeupReason: wake up reason +EXTERNAL uint32_t PowerController_GetLastWakeupReason(PowerController_WakeupReason_t* wakeupReason /* @out */); + +/** Get Last Wakeup key code */ +// @property +// @text getLastWakeupKeyCode +// @brief Get the key code that can be used for wakeup +// @param keycode: Key code for wakeup +EXTERNAL uint32_t PowerController_GetLastWakeupKeyCode(int* keycode /* @out */); + +/** Request Reboot with PowerManager */ +// @text reboot +// @brief Reboot device +// @param rebootRequestor: null terminated string identifier for the entity requesting the reboot. +// @param rebootReasonCustom: custom-defined reason for the reboot, provided as a null terminated string. +// @param rebootReasonOther: null terminated string describing any other reasons for the reboot. +EXTERNAL uint32_t PowerController_Reboot(const char* rebootRequestor /* @in */, const char* rebootReasonCustom /* @in */, const char* rebootReasonOther /* @in */); + +/** Set Network Standby Mode */ +// @property +// @text setNetworkStandbyMode +// @brief Set the standby mode for Network +// @param standbyMode: Network standby mode +EXTERNAL uint32_t PowerController_SetNetworkStandbyMode(const bool standbyMode /* @in */); + +/** Get Network Standby Mode */ +// @text getNetworkStandbyMode +// @brief Get the standby mode for Network +// @param standbyMode: Network standby mode +EXTERNAL uint32_t PowerController_GetNetworkStandbyMode(bool* standbyMode /* @out */); + +/** Set Wakeup source configuration */ +// @text setWakeupSrcConfig +// @brief Set the source configuration for device wakeup +// @param powerMode: power mode +// @param wakeSrcType: source type +// @param config: config +EXTERNAL uint32_t PowerController_SetWakeupSrcConfig(const int powerMode /* @in */, const int wakeSrcType /* @in */, int config /* @in */); + +/** Get Wakeup source configuration */ +// @text getWakeupSrcConfig +// @brief Get the source configuration for device wakeup +// @param powerMode: power mode +// @param srcType: source type +// @param config: config +EXTERNAL uint32_t PowerController_GetWakeupSrcConfig(int* powerMode /* @out */, int* srcType /* @out */, int* config /* @out */); + +/** Initiate System mode change */ +// @text PowerController_SetSystemMode +// @brief System mode change +// @param oldMode: current mode +// @param newMode: new mode +EXTERNAL uint32_t PowerController_SetSystemMode(const PowerController_SystemMode_t currentMode /* @in */, const PowerController_SystemMode_t newMode /* @in */); + +/** Get Power State before last reboot */ +// @text PowerController_GetPowerStateBeforeReboot +// @brief Get Power state before last reboot +// @param powerStateBeforeReboot: power state +EXTERNAL uint32_t PowerController_GetPowerStateBeforeReboot(PowerController_PowerState_t* powerStateBeforeReboot /* @out */); + +/* Callback data types for event notifications from power manager plugin */ + +// @brief Operational state changed event +// @param isOperational: true if PowerManager plugin is activated, false otherwise +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_OperationalStateChangeCb)(bool isOperational, void* userdata); + +// @brief Power mode changed +// @param currentState: Current Power State +// @param newState: New Power State +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_PowerModeChangedCb)(const PowerController_PowerState_t currentState, const PowerController_PowerState_t newState, void* userdata); + +// @brief Power mode Pre-change event +// @param currentState: Current Power State +// @param newState: Changing power state to this New Power State +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_PowerModePreChangeCb)(const PowerController_PowerState_t currentState, const PowerController_PowerState_t newState, void* userdata); + +// @brief Deep sleep timeout event +// @param wakeupTimeout: Deep sleep wakeup timeout in seconds +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_DeepSleepTimeoutCb)(const int wakeupTimeout, void* userdata); + +// @brief Network Standby Mode changed event - only on XIone +// @param enabled: network standby enabled or disabled +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_NetworkStandbyModeChangedCb)(const bool enabled, void* userdata); + +// @brief Thermal Mode changed event +// @param currentThermalLevel: current thermal level +// @param newThermalLevel: new thermal level +// @param currentTemperature: current temperature +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_ThermalModeChangedCb)(const PowerController_ThermalTemperature_t currentThermalLevel, const PowerController_ThermalTemperature_t newThermalLevel, const float currentTemperature, void* userdata); + +// @brief Reboot begin event +// @param rebootReasonCustom: Reboot reason custom +// @param rebootReasonOther: Reboot reason other +// @param rebootRequestor: Reboot requested by +// @param userdata: opaque data, client can use it to have context to callbacks +typedef void (*PowerController_RebootBeginCb)(const char* rebootReasonCustom, const char* rebootReasonOther, const char* rebootRequestor, void* userdata); + +/* Type defines for callbacks / notifications */ +/* userdata in all callbacks are opaque, clients can use it to have context to callbacks */ + +/** Register for PowerManager plugin operational state change event callback, for initial state use `PowerController_IsOperational` call */ +EXTERNAL uint32_t PowerController_RegisterOperationalStateChangeCallback(PowerController_OperationalStateChangeCb callback, void* userdata); +/** UnRegister (previously registered) PowerManager plugin operational state change event callback */ +EXTERNAL uint32_t PowerController_UnRegisterOperationalStateChangeCallback(PowerController_OperationalStateChangeCb callback); +/** Register for PowerMode changed callback */ +EXTERNAL uint32_t PowerController_RegisterPowerModeChangedCallback(PowerController_PowerModeChangedCb callback, void* userdata); +/** UnRegister (previously registered) PowerMode changed callback */ +EXTERNAL uint32_t PowerController_UnRegisterPowerModeChangedCallback(PowerController_PowerModeChangedCb callback); +/** Register for PowerMode pre-change callback */ +EXTERNAL uint32_t PowerController_RegisterPowerModePreChangeCallback(PowerController_PowerModePreChangeCb callback, void* userdata); +/** UnRegister (previously registered) PowerMode pre-change callback */ +EXTERNAL uint32_t PowerController_UnRegisterPowerModePreChangeCallback(PowerController_PowerModePreChangeCb callback); +/** Register for PowerMode pre-change callback */ +EXTERNAL uint32_t PowerController_RegisterDeepSleepTimeoutCallback(PowerController_DeepSleepTimeoutCb callback, void* userdata); +/** UnRegister (previously registered) DeepSleep Timeout callback */ +EXTERNAL uint32_t PowerController_UnRegisterDeepSleepTimeoutCallback(PowerController_DeepSleepTimeoutCb callback); +/** Register for Network Standby Mode changed event - only on XIone */ +EXTERNAL uint32_t PowerController_RegisterNetworkStandbyModeChangedCallback(PowerController_NetworkStandbyModeChangedCb callback, void* userdata); +/** UnRegister (previously registered) Network Standby Mode changed callback */ +EXTERNAL uint32_t PowerController_UnRegisterNetworkStandbyModeChangedCallback(PowerController_NetworkStandbyModeChangedCb callback); +/** Register for Thermal Mode changed event callback */ +EXTERNAL uint32_t PowerController_RegisterThermalModeChangedCallback(PowerController_ThermalModeChangedCb callback, void* userdata); +/** UnRegister (previously registered) Thermal Mode changed event callback */ +EXTERNAL uint32_t PowerController_UnRegisterThermalModeChangedCallback(PowerController_ThermalModeChangedCb callback); +/** Register for reboot start event callback */ +EXTERNAL uint32_t PowerController_RegisterRebootBeginCallback(PowerController_RebootBeginCb callback, void* userdata); +/** UnRegister (previously registered) reboot start event callback */ +EXTERNAL uint32_t PowerController_UnRegisterRebootBeginCallback(PowerController_RebootBeginCb callback); + +#ifdef __cplusplus +}; // extern "C" +#endif + +#endif // POWERMANAGER_CLIENT_H diff --git a/src/unittest/stubs/powerctrl_stubs.cpp b/src/unittest/stubs/powerctrl_stubs.cpp new file mode 100644 index 000000000..9f271d218 --- /dev/null +++ b/src/unittest/stubs/powerctrl_stubs.cpp @@ -0,0 +1,49 @@ +/* + * Copyright 2025 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "power_controller.h" + +void PowerController_Init() +{ + +} + +void PowerController_Term() +{ + +} + +uint32_t PowerController_Connect() +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_RegisterPowerModeChangedCallback(PowerController_PowerModeChangedCb callback, void* userdata) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_UnRegisterPowerModeChangedCallback(PowerController_PowerModeChangedCb callback) +{ + return POWER_CONTROLLER_ERROR_NONE; +} + +uint32_t PowerController_GetPowerState(PowerController_PowerState_t* currentState, PowerController_PowerState_t* previousState) +{ + return POWER_CONTROLLER_ERROR_NONE; +} \ No newline at end of file diff --git a/src/unittest/stubs/rbus/include/rbus.h b/src/unittest/stubs/rbus/include/rbus.h index ebc056129..c2d14cb64 100644 --- a/src/unittest/stubs/rbus/include/rbus.h +++ b/src/unittest/stubs/rbus/include/rbus.h @@ -938,12 +938,21 @@ rbusError_t rbus_get( * RBUS_ERROR_ELEMENT_DOES_NOT_EXIST: Data Element was not previously registered. * RBUS_ERROR_DESTINATION_NOT_REACHABLE: Destination element was not reachable. */ -rbusError_t rbus_getExt( +static inline rbusError_t rbus_getExt( rbusHandle_t handle, int paramCount, char const** paramNames, int *numProps, - rbusProperty_t* properties); + rbusProperty_t* properties) +{ + (void)handle; + (void)paramCount; + (void)paramNames; + (void)numProps; + (void)properties; + + return RBUS_ERROR_SUCCESS; +} /** @fn rbusError_t rbus_getBoolean( * rbusHandle_t handle, diff --git a/src/unittest/stubs/rbus/include/rbus_property.h b/src/unittest/stubs/rbus/include/rbus_property.h index 4ba5cb32e..b415dcbc9 100644 --- a/src/unittest/stubs/rbus/include/rbus_property.h +++ b/src/unittest/stubs/rbus/include/rbus_property.h @@ -61,7 +61,14 @@ typedef struct _rbusProperty* rbusProperty_t; * If the value is NULL, the property's value will be NULL. * @return The new property */ -rbusProperty_t rbusProperty_Init(rbusProperty_t* pproperty, char const* name, rbusValue_t value); +static inline rbusProperty_t rbusProperty_Init(rbusProperty_t* pproperty, char const* name, rbusValue_t value) +{ + (void)pproperty; + (void)name; + (void)value; + + return NULL; +} /** @name rbusProperty_Init[Type] * @brief These function allocate and initialize a property @@ -109,7 +116,10 @@ void rbusProperty_Retain(rbusProperty_t property); * a property that was retained with either rbusProperty_Init or rbusProperty_Retain. * @param property the property to release */ -void rbusProperty_Release(rbusProperty_t property); +static inline void rbusProperty_Release(rbusProperty_t property) +{ + (void)property; +} void rbusProperty_Releases(int count, ...); @@ -277,7 +287,11 @@ rbusProperty_t rbusProperty_AppendObject(rbusProperty_t property, char const* na * it should take ownership by calling rbusProperty_Retain and then * when its done with it, call rbusProperty_Release. */ -rbusProperty_t rbusProperty_GetNext(rbusProperty_t property); +static inline rbusProperty_t rbusProperty_GetNext(rbusProperty_t property) +{ + (void)property; + return NULL; +} /** @fn void rbusProperty_SetNext(rbusProperty_t property, rbusProperty_t next) * @brief Set the next property in the list. Properties can be linked together into a list. diff --git a/src/unittest/stubs/rbus/include/rbus_value.h b/src/unittest/stubs/rbus/include/rbus_value.h index e3dcf048f..9cd23c90f 100644 --- a/src/unittest/stubs/rbus/include/rbus_value.h +++ b/src/unittest/stubs/rbus/include/rbus_value.h @@ -337,7 +337,10 @@ void rbusValue_Swap(rbusValue_t* v1, rbusValue_t* v2); * @param str A string representation of the data which will be coerced to the type specified by the type param and assigned to the value. * @return bool true if this function succeeds to coerce the type and set the value or false if it fails */ -bool rbusValue_SetFromString(rbusValue_t value, rbusValueType_t type, const char* str); +static inline bool rbusValue_SetFromString(rbusValue_t value, rbusValueType_t type, const char* str) +{ + return true; +} /** @fn void rbusValue_fwrite(rbusValue_t obj, int depth, FILE* fout) * @brief A debug utility function to write the value as a string to a file stream. diff --git a/src/unittest/stubs/rdk_debug.h b/src/unittest/stubs/rdk_debug.h index b721e2af1..040eb9a7d 100644 --- a/src/unittest/stubs/rdk_debug.h +++ b/src/unittest/stubs/rdk_debug.h @@ -28,6 +28,7 @@ #define RDK_LOG_INFO 3 #define RDK_LOG_WARN 4 #define RDK_LOG_ERROR 5 +#define RDK_LOG_TRACE2 6 #define rdk_logger_init(DEBUG_INI_NAME) ; @@ -43,6 +44,9 @@ else if (( level == RDK_LOG_ERROR )) { \ printf("ERROR: %s: ", module); \ } \ + else if (( level == RDK_LOG_TRACE1 )) { \ + printf("TRACE: %s: ", module); \ + } \ printf(__VA_ARGS__); \ } while (0) diff --git a/src/unittest/stubs/remote_debugger.json b/src/unittest/stubs/remote_debugger.json new file mode 100644 index 000000000..1f36b579c --- /dev/null +++ b/src/unittest/stubs/remote_debugger.json @@ -0,0 +1,68 @@ +{ + "DebugCategory": { + "DebugIssueType": { + "DebugCommands": "command1;command2;commmand3", + "DebugTimeout" : 10 + } + }, + "Sanity": { + "Check" : { + "Commands" : [ "rm -rf", "kill", "pkill", "iptables", "ip6tables" ] + } + }, + "Device" : { + "Info" : { + "Commands": "cat /version.txt;cat /etc/device.properties;uname -r", + "Timeout" : 10 + }, + "Uptime" : { + "Commands": "uptime", + "Timeout" : 10 + }, + "Dump" : { + "Commands": "tcpdump -w RRD_LOCATION/capture.pcap &", + "Timeout" : 10 + } + }, + "Command" : { + "Harm" : { + "Commands": "rm -rf", + "Timeout" : 10 + } + }, + "Process" : { + "ProcessStatus" : { + "Commands": "cat /opt/logs/top_log.txt*", + "Timeout" : 10 + }, + "ServiceStatus" : { + "Commands": "systemctl list-units --type=service --all", + "Timeout" : 10 + } + }, + "DeepSleep": { + "Audio" : { + "AudioStatus" : { + "Commands": "cat /sys/class/avsync_session0/session_stat;cat /sys/class/vdec/vdec_status;hal_dump", + "Timeout" : 10 + } + }, + "Video" : { + "VideoStatus" : { + "Commands": "cat /sys/class/avsync_session0/session_stat;cat /sys/class/vdec/vdec_status;hal_dump", + "Timeout" : 10 + } + }, + "Process" : { + "ProcessStatus" : { + "Commands": "cat /opt/logs/top_log.txt*", + "Timeout" : 10 + }, + "ServiceStatus" : { + "Commands": "systemctl list-units --type=service --all", + "Timeout" : 10 + } + + } + } +} diff --git a/src/unittest/stubs/rfcapi.h b/src/unittest/stubs/rfcapi.h index 161b7bb31..b46c45c41 100644 --- a/src/unittest/stubs/rfcapi.h +++ b/src/unittest/stubs/rfcapi.h @@ -63,15 +63,20 @@ typedef struct _RFC_Param_t { #ifdef RDKC int getRFCParameter(const char* pcParameterName, RFC_ParamData_t *pstParamData); #else -WDMP_STATUS getRFCParameter(const char *pcCallerID, const char* pcParameterName, RFC_ParamData_t *pstParamData); -WDMP_STATUS setRFCParameter(const char *pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType); +//WDMP_STATUS getRFCParameter(const char *pcCallerID, const char* pcParameterName, RFC_ParamData_t *pstParamData); +//WDMP_STATUS setRFCParameter(const char *pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType); -WDMP_STATUS setRFCParameter(const char *pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) +static inline WDMP_STATUS setRFCParameter(const char *pcCallerID, const char* pcParameterName, const char* pcParameterValue, DATA_TYPE eDataType) { WDMP_STATUS status = WDMP_SUCCESS; return status; } +static inline WDMP_STATUS getRFCParameter(const char *pcCallerID, const char* pcParameterName, RFC_ParamData_t *pstParamData) +{ + WDMP_STATUS status = WDMP_SUCCESS; + return status; +} const char* getRFCErrorString(WDMP_STATUS code); bool isRFCEnabled(const char *); bool isFileInDirectory(const char *, const char *); diff --git a/src/unittest/stubs/rfcdefaults.ini b/src/unittest/stubs/rfcdefaults.ini index 1cedddc0d..a3713354e 100644 --- a/src/unittest/stubs/rfcdefaults.ini +++ b/src/unittest/stubs/rfcdefaults.ini @@ -1 +1,2 @@ Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable=false +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable=true diff --git a/src/unittest/stubs/tr181store.ini b/src/unittest/stubs/tr181store.ini index 1cedddc0d..6e0b14787 100644 --- a/src/unittest/stubs/tr181store.ini +++ b/src/unittest/stubs/tr181store.ini @@ -1 +1,9 @@ Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable=false +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKRemoteDebugger.Enable=false +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed=1280000 +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName=comcast +Device.IP.InterfaceNumberOfEntries=4 +Device.DeviceInfo.X_COMCAST-COM_STB_MAC=A84A6388E9B5 +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.Enable=true +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpStart=300 +Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Canary.wakeUpEnd=480 diff --git a/src/unittest/stubs/wrp-c.h b/src/unittest/stubs/wrp-c.h new file mode 100644 index 000000000..ffab9bf56 --- /dev/null +++ b/src/unittest/stubs/wrp-c.h @@ -0,0 +1,298 @@ +/** + * Copyright 2016 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef __WRP_C_H__ +#define __WRP_C_H__ + +#include +#include +#include +#include "wdmp-c.h" + +/*----------------------------------------------------------------------------*/ +/* Macros */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Data Structures */ +/*----------------------------------------------------------------------------*/ +enum wrp_msg_type { + WRP_MSG_TYPE__AUTH = 2, + WRP_MSG_TYPE__REQ = 3, + WRP_MSG_TYPE__EVENT = 4, + WRP_MSG_TYPE__CREATE = 5, + WRP_MSG_TYPE__RETREIVE = 6, + WRP_MSG_TYPE__UPDATE = 7, + WRP_MSG_TYPE__DELETE = 8, + WRP_MSG_TYPE__SVC_REGISTRATION = 9, + WRP_MSG_TYPE__SVC_ALIVE = 10, + WRP_MSG_TYPE__UNKNOWN = 200 +}; + +enum wrp_format { + WRP_BYTES = 0, + WRP_BASE64 = 1, + WRP_STRING = 2 +}; + +enum wrp_device_id_element { + WRP_ID_ELEMENT__SCHEME = 0, + WRP_ID_ELEMENT__ID = 1, + WRP_ID_ELEMENT__SERVICE = 2, + WRP_ID_ELEMENT__APPLICATION = 3 +}; + +enum wrp_token_name { + SOURCE = 0, + DEST = 1 +}; + +struct wrp_auth_msg { + int status; +}; + +typedef struct headers_struct { + size_t count; + // Flexible Array Must be the last element + char *headers[]; +} headers_t; + +typedef struct partners_struct { + size_t count; + char *partner_ids[]; +} partners_t; + +struct data { + char *name; + char *value; +}; + +typedef struct data_struct { + size_t count; + struct data *data_items; +} data_t; + +struct wrp_req_msg { + char *transaction_uuid; + char *content_type; + char *accept; + char *source; + char *dest; + partners_t *partner_ids; + headers_t *headers; /* NULL terminated list */ + data_t *metadata; + bool include_spans; + money_trace_spans spans; + int qos; + int rdr; + void *payload; + size_t payload_size; +}; + +struct wrp_event_msg { + char *content_type; + char *source; + char *dest; + partners_t *partner_ids; + int qos; + char *transaction_uuid; + headers_t *headers; /* NULL terminated list */ + data_t *metadata; + void *payload; + size_t payload_size; + char *session_id; + int rdr; +}; + +struct wrp_crud_msg { + char *content_type; + char *accept; + char *transaction_uuid; + char *source; + char *dest; + partners_t *partner_ids; + headers_t *headers; /* NULL terminated list */ + data_t *metadata; + bool include_spans; + money_trace_spans spans; + int status; + int rdr; + int qos; + char *path; + void *payload; + size_t payload_size; +}; + +struct wrp_svc_registration_msg { + char *service_name; + char *url; +}; + +typedef struct { + enum wrp_msg_type msg_type; + + union { + struct wrp_auth_msg auth; + struct wrp_req_msg req; + struct wrp_event_msg event; + struct wrp_crud_msg crud; + struct wrp_svc_registration_msg reg; + } u; +} wrp_msg_t; + +/*----------------------------------------------------------------------------*/ +/* File Scoped Variables */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------------*/ +/* none */ + +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ + +/** + * Converts one of the wrp data structures into the sequence of bytes + * representation. + * + * @note If the value returned is greater than 0, the value pointed at by + * bytes must be freed using free() by the caller. + * + * @param msg [in] the wrp_msg_t structure to convert + * @param fmt [in] the format the output should be converted into + * @param bytes [out] the resulting bytes (not changed on error) + * + * @return the length of the bytes if successful or less than 1 otherwise + */ +ssize_t wrp_struct_to( const wrp_msg_t *msg, const enum wrp_format fmt, + void **bytes ); + +/** + * Converts a sequence of bytes into a wrp_msg_t if possible. + * + * @note If the value returned is not NULL, the resulting structure must + * be freed using the wrp_free_struct() function. + * + * @note fmt may only be: WRP_BYTES or WRP_BASE64. + * + * @param bytes [in] the sequence of bytes to process + * @param length [in] the length of the bytes passed in + * @param fmt [in] the format the input should be converted from + * @param msg [out] the resulting wrp_msg_t structure if successful + * unchanged otherwise (not changed on error) + * + * @return the number of bytes 'consumed' by making this transformation if + * successful, less than 1 otherwise + */ +ssize_t wrp_to_struct( const void *bytes, const size_t length, + const enum wrp_format fmt, + wrp_msg_t **msg ); + + +/** + * Converts a wrp_msg_t structure into a printable string. + * + * @note If the value returned is greater than 0, the value pointed at by + * bytes must be freed using free() by the caller. + * + * @param msg [in] the wrp_msg_t structure to convert + */ +char* wrp_struct_to_string( const wrp_msg_t *msg ); + + +/** + * Free the wrp_msg_t structure if allocated by the wrp-c library. + * + * @note Do not call this function on the wrp_msg_t structure if the wrp-c + * library did not create the structure! + * + * @param msg [in] the wrp_msg_t structure to free + */ +void wrp_free_struct( wrp_msg_t *msg ); + +/** + * Encode/pack only metadata from wrp_msg_t structure. + * + * @note Do not call free of output data in failure case! + * + * @param msg [in] packData the data_t structure to pack/encode + * @param msg [out] the encoded output + * @return encoded buffer size or less than 1 in failure case + */ + +ssize_t wrp_pack_metadata( const data_t *packData, void **data ); + +/** + * @brief appendEncodedData function to append two encoded buffer and change MAP size accordingly. + * + * @note appendEncodedData function allocates memory for buffer, caller needs to free the buffer(appendData)in + * both success or failure case. use wrp_free_struct() for free + * + * @param[in] encodedBuffer msgpack object (first buffer) + * @param[in] encodedSize is size of first buffer + * @param[in] metadataPack msgpack object (second buffer) + * @param[in] metadataSize is size of second buffer + * @param[out] appendData final encoded buffer after append + * @return appended total buffer size or less than 1 in failure case + */ + +size_t appendEncodedData( void **appendData, void *encodedBuffer, size_t encodedSize, void *metadataPack, size_t metadataSize ); + +/** + * Find the destination of a wrp_msg_t + * + * @param msg [in] the wrp_msg_t structure to examine + * @return pointer to destination, or NULL if there is no + * destination for this message type + */ +const char *wrp_get_msg_dest( const wrp_msg_t *wrp_msg ); + +/** + * Find the source of a wrp_msg_t + * + * @param msg [in] the wrp_msg_t structure to examine + * @return pointer to source, or NULL if there is no + * source for this message type + */ + +/** + * Find an element of the source or destination of a wrp_msg_t + * + * @note Returned memory must be freed using free(). + * + * @param [in] the element requested to parse + * @param msg [in] the wrp_msg_t structure to examine + * @param [in] the wrp_token source or destination to examine + * + * @return pointer to the element requested, or NULL otherwise + */ +char *wrp_get_msg_element( const enum wrp_device_id_element element, + const wrp_msg_t *wrp_msg, const enum wrp_token_name wrp_token ); + +/** + * Check to see if the service matches based on the specified device_id. + * + * @param [in] service the service name check the device_id for + * @param [in] device_id the device-id string to examine looking for the service + * + * @return 0 if there is a match, -1 otherwise. + */ +int wrp_does_service_match( const char *service, const char *device_id ); +#endif diff --git a/test/functional-tests/features/tr69hostif_bootup_sequence.feature b/test/functional-tests/features/tr69hostif_bootup_sequence.feature index fe7b2dc83..b3b9b3de1 100644 --- a/test/functional-tests/features/tr69hostif_bootup_sequence.feature +++ b/test/functional-tests/features/tr69hostif_bootup_sequence.feature @@ -25,3 +25,111 @@ Feature: tr69hostif runs as daemon to collect data Then the tr69hostif should be running as a daemon And when the tr69hostif is initialized successfully Then the tr69hostif validation is done for all instance + + Scenario: json handler thread initialization + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "SERVER: Started server successfully." message + + Scenario: http server thread initialization + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "SERVER: Started server successfully." message + + Scenario: thread creation + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should not log the "pthread_create() failed" message + + Scenario: parodus initialization + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "Initiating Connection with PARODUS success.." message + + Scenario: rbus initialization + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should not log the "[rbusdml] Failed to initialized, rbus_checkStatus() returned with status" message + And should not log the "consumer: rbus_open failed" message + And should log the "[rbusdml]Successfully get the complete parameter list" message + And should log the "rbus_regDataElements registered successfully" message + + Scenario: hostif initialize config manager status + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should not log the "Failed to hostIf_initalize_ConfigManger()" message + + Scenario: Successful PwrContInterface thread initialization + When a new thread is requested with valid configuration + Then the system initializes the thread + And should log the "created getPwrContInterface thread.." message + And marks the thread as ready for execution + + Scenario: Successful ethernet thread initialization + When a new thread is requested with valid configuration Then the system initializes the thread + And should log the "checkForUpdates] Got lock.." message + And marks the thread as ready for execution + + Scenario: Data model merge + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "Entering data model merge process" message + And should log the "Merged XML files successfully into /tmp/data-model.xml" message + And should log the "Successfully merged Data Model" message + + Scenario: Data model initialization + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "Successfully initialize Data Model" message + + Scenario: Bootstrap configuration + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "Bootstrap Properties File" message + And should log the "/opt/secure/RFC/bootstrap.ini" message + + Scenario: device manager initialization + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "Device manager Initialized success" message + And should log the "break loop" message + + Scenario: webpa process requests + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "Starting WEBPA Parodus Connections" message + + Scenario: PowerController initialization + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "start PowerController_Init()" message + And should log the "completed PowerController_Init()" message + And should log the "Got the powercontroller interface" message + + Scenario: power mode initialization + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And should log the "Registering power mode change callback" message + And should log the "Registered power mode change callback" message + + + Scenario: rfc_defaults_ini file + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And the /tmp/rfcdefaults.ini file should exist + + diff --git a/test/functional-tests/features/tr69hostif_deviceip.feature b/test/functional-tests/features/tr69hostif_deviceip.feature new file mode 100644 index 000000000..fee15f3c9 --- /dev/null +++ b/test/functional-tests/features/tr69hostif_deviceip.feature @@ -0,0 +1,30 @@ +#################################################################################### +# If not stated otherwise in this file or this component's Licenses.txt file the +# following copyright and licenses apply: +# +# Copyright 2024 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#################################################################################### + + +Feature: tr69hostif runs as daemon to collect data + + Scenario: tr69hostif runs as daemon + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + Then the tr69hostif Profile Initialization is done for Device.DeviceInfo + Then the tr69hostif validation is done for Device.DeviceInfo get/set handlers + Then the tr69hostif validation is done for Device.IP get/set handlers + Then the tr69hostif validation is done for Device.Services get/set handlers diff --git a/test/functional-tests/features/tr69hostif_handlers_communications.feature b/test/functional-tests/features/tr69hostif_handlers_communications.feature index 082fcc725..7b39efcc4 100644 --- a/test/functional-tests/features/tr69hostif_handlers_communications.feature +++ b/test/functional-tests/features/tr69hostif_handlers_communications.feature @@ -30,3 +30,11 @@ Feature: tr69hostif runs as daemon to collect data Then the tr69hostif validation is done for RFC get/set handlers Then the tr69hostif validation is done for Non RFC get/set handlers Then the tr69hostif validation is done for Bootstrap get/set handlers + + Scenario: bootstrap files exist + Given When the tr69hostif binary is invoked + Then the tr69hostif should be running as a daemon + And when the tr69hostif is initialized successfully + And the /opt/secure/RFC/bootstrap.ini file should exist + And the /opt/secure/RFC/bootstrap.journal file should exist + diff --git a/test/functional-tests/features/tr69hostif_webpa.feature b/test/functional-tests/features/tr69hostif_webpa.feature new file mode 100644 index 000000000..e9ba25db3 --- /dev/null +++ b/test/functional-tests/features/tr69hostif_webpa.feature @@ -0,0 +1,59 @@ +#################################################################################### +# If not stated otherwise in this file or this component's Licenses.txt file the +# following copyright and licenses apply: +# +# Copyright 2024 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#################################################################################### + + +Feature: WebPA Set Get using mock parodus + + Background: + Given the mock parodus executable is avaliable at "/usr/local/bin/parodus" + And it accepts payloads as input + + + Scenario: Set a WebPA parameter using mock parodus + Given a valid WebPA set request payload: + """ + { + "command": "SET", + "parameters": [ + { + "name": "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable", + "value": "false", + "dataType": 3 + } + ] + } + """ + When I execute the mock parodus with the payload + Then the response should indicate success + And the parameter "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable" should be "false" + + Scenario: Get a WebPA parameter using mock parodus + Given a valid WebPA get request payload: + """ + { + "command": "GET", + "names": [ + "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable" + ] + } + """ + When I execute the mock parodus with the payload + Then the response should indicate success + And the returned value should be "false" + diff --git a/test/functional-tests/tests/basic_constants.py b/test/functional-tests/tests/basic_constants.py index 3b10f8d0d..9bad64f88 100644 --- a/test/functional-tests/tests/basic_constants.py +++ b/test/functional-tests/tests/basic_constants.py @@ -41,8 +41,10 @@ T2_REPORT_PROFILE_PARAM_MSG_PCK="Device.X_RDKCENTRAL-COM_T2.ReportProfilesMsgPack" T2_TEMP_REPORT_PROFILE_PARAM="Device.X_RDKCENTRAL-COM_T2.Temp_ReportProfiles" RBUS_EXCEPTION_STRING = "Failed to get the data" +RBUS_SUCCESS_STRING = "setvalues succeeded.." LOG_FILE = "/opt/logs/tr69hostif.log.0" +PARODUS_LOG_FILE = "/opt/logs/parodus.log" DATA_LAKE_URL = "https://mockxconf:50051" DL_ADMIN_URL = "https://mockxconf:50051/adminSupport" diff --git a/test/functional-tests/tests/helper_functions.py b/test/functional-tests/tests/helper_functions.py index 94c5093d1..c66a1a6ac 100644 --- a/test/functional-tests/tests/helper_functions.py +++ b/test/functional-tests/tests/helper_functions.py @@ -30,6 +30,7 @@ def run_module(module_path: str): return subprocess.run("{module_path}", shell=True) + #tr69hostif def kill_module(module: str, signal: int=9): print(f"Recived Signal to kill {module} {signal} with pid {get_pid({module})}") @@ -82,7 +83,7 @@ def get_process_uptime(pid): def get_pid(name: str): return subprocess.run(f"pidof {name}", shell=True, capture_output=True).stdout.decode('utf-8').strip() -def clear_T2logs(): +def clear_tr69hostiflogs(): subprocess.run(f"echo '' > {LOG_FILE}", shell=True) def grep_log_file(search: str, log_file: str): @@ -96,7 +97,7 @@ def remove_T2bootup_flag(): except: pass -def grep_T2logs(search: str): +def grep_tr69hostiflogs(search: str): search_result = "" search_pattern = re.compile(re.escape(search), re.IGNORECASE) try: @@ -166,3 +167,14 @@ def run_shell_command(command): result = subprocess.run(command, shell=True, capture_output=True, text=True) return result.stdout.strip() +def grep_paroduslogs(search: str): + search_result = "" + search_pattern = re.compile(re.escape(search), re.IGNORECASE) + try: + with open(PARODUS_LOG_FILE, 'r', encoding='utf-8', errors='ignore') as file: + for line_number, line in enumerate(file, start=1): + if search_pattern.search(line): + search_result = search_result + " \n" + line + except Exception as e: + print(f"Could not read file {PARODUS_LOG_FILE}: {e}") + return search_result diff --git a/test/functional-tests/tests/profile_helper_functions.py b/test/functional-tests/tests/profile_helper_functions.py index f0b1116df..76bf43b1b 100644 --- a/test/functional-tests/tests/profile_helper_functions.py +++ b/test/functional-tests/tests/profile_helper_functions.py @@ -30,8 +30,8 @@ print("Execute L2 Test suit for tr69hostif ") print("Clearing T2 logs") - clear_T2logs() + clear_tr69hostiflogs() print("Messages after clearing") - response = grep_T2logs(GREP_STRING) + response = grep_tr69hostiflogs(GREP_STRING) print(response) diff --git a/test/functional-tests/tests/test_bootup_sequence.py b/test/functional-tests/tests/test_bootup_sequence.py index a3291d01c..b389c6447 100644 --- a/test/functional-tests/tests/test_bootup_sequence.py +++ b/test/functional-tests/tests/test_bootup_sequence.py @@ -26,6 +26,8 @@ MODULE_NAME = "tr69hostif" + + def profile_init_run_command(): """Run the rbuscli curl command and return the result.""" command = [ @@ -57,27 +59,27 @@ def is_process_active(): def test_check_tr69_json_handler(): is_process_active() JSON_SUCCESS_MSG = "SERVER: Started server successfully." - assert JSON_SUCCESS_MSG in grep_T2logs(JSON_SUCCESS_MSG) + assert JSON_SUCCESS_MSG in grep_tr69hostiflogs(JSON_SUCCESS_MSG) @pytest.mark.run(order=2) def test_check_http_server_status(): start_time = time.time(); is_process_active() HTTP_SUCCESS_MSG = "SERVER: Started server successfully." - assert HTTP_SUCCESS_MSG in grep_T2logs(HTTP_SUCCESS_MSG) + assert HTTP_SUCCESS_MSG in grep_tr69hostiflogs(HTTP_SUCCESS_MSG) print("--- %s seconds ---" % (time.time() - start_time)) @pytest.mark.run(order=3) def test_check_paradous_status(): is_process_active() PD_SUCCESS_MSG = "Initiating Connection with PARODUS success.." - assert PD_SUCCESS_MSG in grep_T2logs(PD_SUCCESS_MSG) + assert PD_SUCCESS_MSG in grep_tr69hostiflogs(PD_SUCCESS_MSG) @pytest.mark.run(order=4) def test_check_shutdown_thread_status(): is_process_active() SHUTDOWN_ERROR_MSG = "pthread_create() failed" - assert SHUTDOWN_ERROR_MSG not in grep_T2logs(SHUTDOWN_ERROR_MSG) + assert SHUTDOWN_ERROR_MSG not in grep_tr69hostiflogs(SHUTDOWN_ERROR_MSG) #Verify Initialization are success @pytest.mark.run(order=5) @@ -87,20 +89,172 @@ def test_init_rbus_dml_provider_status(): RBUS2_ERROR_MSG = "consumer: rbus_open failed" RBUS3_SUCCESS_MSG = "[rbusdml]Successfully get the complete parameter list" RBUS4_SUCCESS_MSG = "rbus_regDataElements registered successfully" - assert RBUS1_ERROR_MSG not in grep_T2logs(RBUS1_ERROR_MSG) - assert RBUS2_ERROR_MSG not in grep_T2logs(RBUS2_ERROR_MSG) - assert RBUS3_SUCCESS_MSG in grep_T2logs(RBUS3_SUCCESS_MSG) - assert RBUS4_SUCCESS_MSG in grep_T2logs(RBUS4_SUCCESS_MSG) + assert RBUS1_ERROR_MSG not in grep_tr69hostiflogs(RBUS1_ERROR_MSG) + assert RBUS2_ERROR_MSG not in grep_tr69hostiflogs(RBUS2_ERROR_MSG) + assert RBUS3_SUCCESS_MSG in grep_tr69hostiflogs(RBUS3_SUCCESS_MSG) + assert RBUS4_SUCCESS_MSG in grep_tr69hostiflogs(RBUS4_SUCCESS_MSG) @pytest.mark.run(order=6) def test_hostIf_initalize_ConfigManger_status(): is_process_active() CONFIG_ERROR_MSG = "Failed to hostIf_initalize_ConfigManger()" - assert CONFIG_ERROR_MSG not in grep_T2logs(CONFIG_ERROR_MSG) + assert CONFIG_ERROR_MSG not in grep_tr69hostiflogs(CONFIG_ERROR_MSG) @pytest.mark.run(order=7) +def test_iarm_initialization(): + """Verify IARM bus initialization""" + is_process_active() + IARM_INIT_MSG = "Success 'IARM_Bus_Init(tr69HostIfMgr)'" + THREAD_MSG = "created getPwrContInterface thread.." + + assert IARM_INIT_MSG in grep_tr69hostiflogs("IARM_Bus_Init"), "IARM initialization failed" + assert THREAD_MSG in grep_tr69hostiflogs("getPwrContInterface thread"), "getPwrContInterface thread creation failed" + + +@pytest.mark.run(order=8) +def test_power_controller_thread(): + """Verify getPwrContInterface thread is created""" + is_process_active() + THREAD_MSG = "created getPwrContInterface thread.." + assert THREAD_MSG in grep_tr69hostiflogs(THREAD_MSG), "getPwrContInterface thread creation failed" + +@pytest.mark.run(order=9) +def test_data_model_merge_process(): + """Verify data model merge workflow""" + is_process_active() + MERGE_START_MSG = "Entering data model merge process" + MERGE_SUCCESS_MSG = "Merged XML files successfully into /tmp/data-model.xml" + MERGE_COMPLETE_MSG = "Successfully merged Data Model" + + logs = grep_tr69hostiflogs("merge") + + assert MERGE_START_MSG in logs, "Data model merge process did not start" + assert MERGE_SUCCESS_MSG in logs, "XML merge failed" + assert MERGE_COMPLETE_MSG in logs, "Data model merge did not complete successfully" + + profile_log = grep_tr69hostiflogs("Merging XML files for profile:") + assert profile_log, "Profile information not found in merge logs" + print(f"\nProfile merge info: {profile_log}") + +@pytest.mark.run(order=10) def test_loadDataModel_status(): is_process_active() - DM_SUCCESS_MSG = "Successfully initialize Data Model" - assert DM_SUCCESS_MSG in grep_T2logs(DM_SUCCESS_MSG) + DM_SUCCESS_MSG = "Successfully initialize Data Model" + assert DM_SUCCESS_MSG in grep_tr69hostiflogs(DM_SUCCESS_MSG) + + +@pytest.mark.run(order=11) +def test_ethernet_client_thread(): + """Verify Ethernet client thread starts""" + is_process_active() + ETH_THREAD_MSG = "checkForUpdates] Got lock.." + assert ETH_THREAD_MSG in grep_tr69hostiflogs(ETH_THREAD_MSG), "Ethernet client thread did not start" + +@pytest.mark.run(order=12) +def test_bootstrap_configuration(): + """Verify bootstrap configuration is loaded""" + is_process_active() + BOOTSTRAP_MSG = "Bootstrap Properties File" + BOOTSTRAP_PATH = "/opt/secure/RFC/bootstrap.ini" + + logs = grep_tr69hostiflogs(BOOTSTRAP_MSG) + assert logs, "Bootstrap configuration not loaded" + assert BOOTSTRAP_PATH in logs, f"Bootstrap file path {BOOTSTRAP_PATH} not found" + +@pytest.mark.run(order=13) +def test_device_manager_initialization(): + """Verify device manager (dsClient) initialization""" + is_process_active() + DS_INIT_MSG = "Device manager Initialized success" + DS_BREAK_LOOP_MSG = "break loop" + + logs = grep_tr69hostiflogs("Device manager") + assert DS_INIT_MSG in logs, "Device manager initialization failed" + assert DS_BREAK_LOOP_MSG in logs, "Device manager initialization loop did not break properly" + + +@pytest.mark.run(order=14) +def test_webpa_ready_status(): + """Verify WebPA is ready to process requests""" + is_process_active() + WEBPA_START_MSG = "Starting WEBPA Parodus Connections" + PARODUS_START_MSG = "Starting WEBPA Parodus Connections" + + logs = grep_tr69hostiflogs("parodus") + + assert PARODUS_START_MSG in logs, "Parodus did not start correctly" + assert WEBPA_START_MSG in logs, "WebPA did not start correctly" + + +@pytest.mark.run(order=15) +def test_power_controller_initialization(): + """Verify PowerController initialization completes""" + is_process_active() + PC_START_MSG = "start PowerController_Init()" + PC_COMPLETE_MSG = "completed PowerController_Init()" + PC_INTERFACE_MSG = "Got the powercontroller interface" + + + logs = grep_tr69hostiflogs("PowerController") + + assert PC_START_MSG in logs, "PowerController initialization did not start" + assert PC_COMPLETE_MSG in logs, "PowerController initialization did not complete" + assert PC_INTERFACE_MSG in logs, "PowerController interface not acquired" + +@pytest.mark.run(order=16) +def test_power_mode_initialization(): + """Verify power mode initialization completes""" + is_process_active() + PC_REGISTERING_MSG = "Registering power mode change callback" + PC_CALLBACK_MSG = "Registered power mode change callback" + + logs = grep_tr69hostiflogs("power") + + assert PC_REGISTERING_MSG in logs, "Power mode change callback registration not started" + assert PC_CALLBACK_MSG in logs, "Power mode change callback not registered" + + +@pytest.mark.run(order=17) +def test_no_critical_errors(): + """Verify no critical errors during bootup""" + is_process_active() + + # Check for common critical errors + CRITICAL_ERRORS = [ + "pthread_create() failed", + "Failed to hostIf_initalize_ConfigManger()", + "[rbusdml] Failed to initialized", + "consumer: rbus_open failed", + "FATAL", + "CRITICAL" + ] + + logs = grep_tr69hostiflogs("tr69hostif") + + for error_msg in CRITICAL_ERRORS: + assert error_msg not in logs, f"Critical error found: {error_msg}" + + print("\nNo critical errors found during bootup sequence") + +@pytest.mark.run(order=18) +def test_rfcdefaults_ini_created(): + + RFC_DEFAULTS_FILE = "/tmp/rfcdefaults.ini" + RFC_PARAM_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable" + RFC_PARAM_LINE ="Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Airplay.Enable=false" + EXPECTED_VALUE = "false" + RFC_STORE_LOG_MSG = "Calling getValue in New RFC Store I/O" + # Check if file exists + import os + assert os.path.exists(RFC_DEFAULTS_FILE), f"File {RFC_DEFAULTS_FILE} does not exist" + + with open(RFC_DEFAULTS_FILE, 'r') as f: + file_content = f.read() + assert RFC_PARAM_LINE in file_content, f"Expected parameter '{RFC_PARAM_NAME}' not found in {RFC_DEFAULTS_FILE}" + + #Get the parameter value from that file + param_value = rbus_get_data(RFC_PARAM_NAME) + #Check logs + assert RFC_STORE_LOG_MSG in grep_tr69hostiflogs(RFC_STORE_LOG_MSG), \ + f"RFC Store I/O log message not found in logs" diff --git a/test/functional-tests/tests/test_handlers_communications.py b/test/functional-tests/tests/test_handlers_communications.py index 8daffce8f..c8438ca4a 100644 --- a/test/functional-tests/tests/test_handlers_communications.py +++ b/test/functional-tests/tests/test_handlers_communications.py @@ -24,9 +24,9 @@ from helper_functions import * -@pytest.mark.run(order=8) +@pytest.mark.run(order=19) def test_DeviceInfo_Set_Get_Handler(): - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Telemetry.Version" VERSION_MSG = "2.2.1" rbus_set_data(DATA_ELEMENT_NAME, "string", VERSION_MSG) @@ -35,29 +35,30 @@ def test_DeviceInfo_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert VERSION_MSG in rstdout -@pytest.mark.run(order=9) +@pytest.mark.run(order=20) def test_DeviceTime_Set_Get_Handler(): - #clear_T2logs() - + #clear_tr69hostiflogs() + DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.DHCPv6Client.Enable" SERVER_ELEMENT_NAME = "Device.Time.NTPServer1" - + STATE_MSG = "true" SERVER_IP = "3.236.252.118" - + rbus_set_data(DATA_ELEMENT_NAME, "boolean", STATE_MSG) rstdout = rbus_get_data(DATA_ELEMENT_NAME) assert RBUS_EXCEPTION_STRING not in rstdout assert STATE_MSG in rstdout - + rbus_set_data(SERVER_ELEMENT_NAME, "string", SERVER_IP) rstdout = rbus_get_data(SERVER_ELEMENT_NAME) assert RBUS_EXCEPTION_STRING not in rstdout assert SERVER_IP in rstdout -@pytest.mark.run(order=10) + +@pytest.mark.run(order=21) def test_RFC_Set_Get_Handler(): - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.HdmiCecSink.CECVersion" VERSION_MSG = "1.4" rbus_set_data(DATA_ELEMENT_NAME, "string", VERSION_MSG) @@ -66,7 +67,7 @@ def test_RFC_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert VERSION_MSG in rstdout - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.Enable" STATE_MSG = "true" rbus_set_data(DATA_ELEMENT_NAME, "boolean", STATE_MSG) @@ -75,7 +76,7 @@ def test_RFC_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert STATE_MSG in rstdout - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.TopSpeed" SPEED_LIMIT_MSG = "1280000" rbus_set_data(DATA_ELEMENT_NAME, "int", SPEED_LIMIT_MSG) @@ -83,8 +84,7 @@ def test_RFC_Set_Get_Handler(): rstdout = rbus_get_data(DATA_ELEMENT_NAME) assert RBUS_EXCEPTION_STRING not in rstdout assert SPEED_LIMIT_MSG in rstdout - - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.eMMCFirmware.Version" VERSION_MSG = "08140310" rbus_set_data(DATA_ELEMENT_NAME, "string", VERSION_MSG) @@ -93,7 +93,7 @@ def test_RFC_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert VERSION_MSG in rstdout - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.IncrementalCDL.Enable" CDL_STATE_MSG = "true" rbus_set_data(DATA_ELEMENT_NAME, "boolean", CDL_STATE_MSG) @@ -102,9 +102,9 @@ def test_RFC_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert CDL_STATE_MSG in rstdout -@pytest.mark.run(order=11) +@pytest.mark.run(order=22) def test_NonRFC_Set_Get_Handler(): - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME ="Device.DeviceInfo.X_RDKCENTRAL-COM_IPRemoteSupport.Enable" IPRS_STATE_MSG = "false" rbus_set_data(DATA_ELEMENT_NAME, "boolean", IPRS_STATE_MSG) @@ -113,7 +113,7 @@ def test_NonRFC_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert IPRS_STATE_MSG in rstdout - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME ="Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ForwardSSH.Enable" SSH_STATE_MSG = "false" rbus_set_data(DATA_ELEMENT_NAME, "boolean", SSH_STATE_MSG) @@ -122,7 +122,7 @@ def test_NonRFC_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert SSH_STATE_MSG in rstdout - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME ="Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadDeferReboot" FWDLRBT_STATE_MSG = "false" rbus_set_data(DATA_ELEMENT_NAME, "boolean", FWDLRBT_STATE_MSG) @@ -131,7 +131,7 @@ def test_NonRFC_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert FWDLRBT_STATE_MSG in rstdout - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME ="Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.FirmwareDownloadCompletedNotification" FWDLNOTIF_STATE_MSG = "false" rbus_set_data(DATA_ELEMENT_NAME, "boolean", FWDLNOTIF_STATE_MSG) @@ -140,40 +140,75 @@ def test_NonRFC_Set_Get_Handler(): assert RBUS_EXCEPTION_STRING not in rstdout assert FWDLNOTIF_STATE_MSG in rstdout -@pytest.mark.run(order=12) +@pytest.mark.run(order=23) def test_Bootstrap_Set_Get_Handler(): - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME ="Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerProductName" - PRODUCT_NAME_MSG = "Xfinity" + PRODUCT_NAME_MSG = "TestProduct123" rbus_set_data(DATA_ELEMENT_NAME, "string", PRODUCT_NAME_MSG) # Force reload config fetch from xconf rstdout = rbus_get_data(DATA_ELEMENT_NAME) assert RBUS_EXCEPTION_STRING not in rstdout assert PRODUCT_NAME_MSG in rstdout - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME ="Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.NetflixESNprefix" - ESN_PREFIX_MSG = "CMCSTX" + ESN_PREFIX_MSG = "TESTESN" rbus_set_data(DATA_ELEMENT_NAME, "string", ESN_PREFIX_MSG) # Force reload config fetch from xconf rstdout = rbus_get_data(DATA_ELEMENT_NAME) assert RBUS_EXCEPTION_STRING not in rstdout assert ESN_PREFIX_MSG in rstdout - - #clear_T2logs() + + #clear_tr69hostiflogs() DATA_ELEMENT_NAME ="Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName" - PARTNER_NAME_MSG = "Comcast" + PARTNER_NAME_MSG = "Test" rbus_set_data(DATA_ELEMENT_NAME, "string", PARTNER_NAME_MSG) # Force reload config fetch from xconf rstdout = rbus_get_data(DATA_ELEMENT_NAME) assert RBUS_EXCEPTION_STRING not in rstdout assert PARTNER_NAME_MSG in rstdout - #clear_T2logs() + #clear_tr69hostiflogs() DATA_ELEMENT_NAME ="Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.SsrUrl" - SSR_URL_MSG = "https://ssr.ccp.xcal.tv" + SSR_URL_MSG = "https://ssr.test.tv" rbus_set_data(DATA_ELEMENT_NAME, "string", SSR_URL_MSG) # Force reload config fetch from xconf rstdout = rbus_get_data(DATA_ELEMENT_NAME) assert RBUS_EXCEPTION_STRING not in rstdout assert SSR_URL_MSG in rstdout + +@pytest.mark.run(order=24) +def test_Bootstrap_File_Creation(): + import os + + sleep(5) + + # Verify bootstrap files exist + assert os.path.exists("/opt/secure/RFC/bootstrap.ini"), \ + "bootstrap.ini file was not created" + assert os.path.exists("/opt/secure/RFC/bootstrap.journal"), \ + "bootstrap.journal file was not created" + + # Test that bootstrap parameters can be set via RBUS + TEST_PARAM = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerProductName" + TEST_VALUE = "TestProduct123" + + # Set using standard L2 pattern + rbus_set_data(TEST_PARAM, "string", TEST_VALUE) + + result = rbus_get_data(TEST_PARAM) + assert RBUS_EXCEPTION_STRING not in result, \ + f"RBUS error occurred: {result}" + assert TEST_VALUE in result, \ + f"Expected value '{TEST_VALUE}' not found in result: {result}" + sleep(2) + + # Verify the parameter was written to bootstrap.ini + with open("/opt/secure/RFC/bootstrap.ini", "r") as f: + content = f.read() + assert TEST_VALUE in content, \ + f"Bootstrap parameter not found in file. Content:\n{content}" + + + diff --git a/test/functional-tests/tests/tr69hostif_deviceip.py b/test/functional-tests/tests/tr69hostif_deviceip.py new file mode 100644 index 000000000..a39cba16c --- /dev/null +++ b/test/functional-tests/tests/tr69hostif_deviceip.py @@ -0,0 +1,187 @@ +#################################################################################### +# If not stated otherwise in this file or this component's Licenses file the +# following copyright and licenses apply: +# +# Copyright 2024 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#################################################################################### + + +import subprocess +import pytest +from time import sleep + +from helper_functions import * + +@pytest.mark.run(order=25) +def test_DeviceDefault_Set_Get_Handler(): + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.DeviceInfo.SoftwareVersion" + VERSION_MSG = "99.99.15.07" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert VERSION_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.DeviceInfo.ModelName" + MODEL_NAME = "DOCKER" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert MODEL_NAME in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.DeviceInfo.X_COMCAST-COM_FirmwareFilename" + FW_FILE_NAME = "Platform_Cotainer_1.0.0" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert FW_FILE_NAME in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.MEMSWAP.Enable" + STATUS_MSG = "true" + rbus_set_data(DATA_ELEMENT_NAME, "string", STATUS_MSG) + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert STATUS_MSG in rstdout + + + +@pytest.mark.run(order=26) +def test_DeviceIP_Set_Get_Handler(): + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Prefix.1.Autonomous" + STATUS_MSG = "false" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Address.1.Anycast" + STATUS_MSG = "false" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Address.1.Enable" + STATUS_MSG = "true" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Prefix.1.StaticType" + STATUS_MSG = "Inapplicable" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6AddressNumberOfEntries" + ENTRY_COUNT_MSG = "1" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert ENTRY_COUNT_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Address.1.Origin" + ORIGIN_MSG = "WellKnown" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert ORIGIN_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv4Address.1.Enable" + STATUS_MSG = "true" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Prefix.1.PrefixStatus" + PREFIX_STATUS_MSG = "Preferred" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert PREFIX_STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Address.1.PreferredLifetime" + PREF_LTF_STATUS_MSG = "0001-01-01T00:00:00Z" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert PREF_LTF_STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Enable" + STATUS_MSG = "true" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.IP.Interface.1.IPv6Prefix.1.ValidLifetime" + PREF_LTF_STATUS_MSG = "0001-01-01T00:00:00Z" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert PREF_LTF_STATUS_MSG in rstdout + +@pytest.mark.run(order=27) +def test_DeviceServices_Set_Get_Handler(): + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.Services.STBServiceNumberOfEntries" + STB_ENTRY_COUNT_MSG = "1" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert STB_ENTRY_COUNT_MSG in rstdout + +@pytest.mark.run(order=28) +def test_ReverseSSH_Set_Get_Handler(): + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ReverseSSH.xOpsReverseSshStatus" + SSH_STATUS_MSG = "INACTIVE" + # Force reload config fetch from xconf + rstdout = rbus_get_data(DATA_ELEMENT_NAME) + assert RBUS_EXCEPTION_STRING not in rstdout + assert SSH_STATUS_MSG in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ReverseSSH.xOpsReverseSshTrigger" + SSH_TRG_MSG = "start shorts" + rstdout = rbus_set_data(DATA_ELEMENT_NAME, "string", SSH_TRG_MSG) + # Force reload config fetch from xconf + assert RBUS_SUCCESS_STRING in rstdout + + #clear_T2logs() + DATA_ELEMENT_NAME = "Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.ReverseSSH.xOpsReverseSshArgs" + SSH_ARGS_MSG = "host=mockserver.tv;hostIp=mockserver.xmock.tv;stunnelport=2009;idletimeout=300;revsshport=3008;sshport=2221;user=webpa_user01;" + rstdout = rbus_set_data(DATA_ELEMENT_NAME, "string", SSH_ARGS_MSG) + # Force reload config fetch from xconf + assert RBUS_SUCCESS_STRING in rstdout + diff --git a/test/functional-tests/tests/tr69hostif_webpa.py b/test/functional-tests/tests/tr69hostif_webpa.py new file mode 100644 index 000000000..ff84e968d --- /dev/null +++ b/test/functional-tests/tests/tr69hostif_webpa.py @@ -0,0 +1,320 @@ +#################################################################################### +# If not stated otherwise in this file or this component's Licenses file the +# following copyright and licenses apply: +# +# Copyright 2024 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#################################################################################### + + +import subprocess +import pytest +from time import sleep + +from helper_functions import * + +@pytest.mark.run(order=29) +def test_WebPA_Set_XCONF_URL_Handler(): + print("Starting parodus mock process") + payload = '{"command":"SET","parameters":[{"name":"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Control.XconfUrl","dataType":0,"value":"https://mockurl/featurecontrol/getSettings"}]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + +@pytest.mark.run(order=30) +def test_WebPA_Get_XCONF_URL_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Control.XconfUrl"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + XCONF_URL_STATUS_MSG = '"value":"https://mockurl/featurecontrol/getSettings"' + assert XCONF_URL_STATUS_MSG in grep_paroduslogs(XCONF_URL_STATUS_MSG) + +@pytest.mark.run(order=31) +def test_WebPA_Set_FWUPDATE_Handler(): + print("Starting parodus mock process") + payload = '{"command":"SET","parameters":[{"name":"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable","dataType":3,"value":"false"}]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + +@pytest.mark.run(order=32) +def test_WebPA_Get_FWUPDATE_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.FWUpdate.AutoExcluded.Enable"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + FWUPDATE_STATUS_MSG = '"value":"false"' + assert FWUPDATE_STATUS_MSG in grep_paroduslogs(FWUPDATE_STATUS_MSG) + +@pytest.mark.run(order=33) +def test_WebPA_Set_LOGURL_Handler(): + print("Starting parodus mock process") + payload = '{"command":"SET","parameters":[{"name":"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.LogUpload.LogServerUrl","dataType":0,"value":"logs.mock.tv"}]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + + +@pytest.mark.run(order=34) +def test_WebPA_Get_LOGURL_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.LogUpload.LogServerUrl"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + LOGURL_MSG = '"value":"logs.mock.tv"' + assert LOGURL_MSG in grep_paroduslogs(LOGURL_MSG) + + +@pytest.mark.run(order=35) +def test_WebPA_Get_SPEED_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SWDLSpLimit.LowSpeed"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + SPEED_STATUS_MSG = '"value":"12800"' + assert SPEED_STATUS_MSG in grep_paroduslogs(SPEED_STATUS_MSG) + + +@pytest.mark.run(order=36) +def test_WebPA_Get_FW_PROTOCOL_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadProtocol"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + FWDL_PROTOCOL_MSG = '"value":"http"' + assert FWDL_PROTOCOL_MSG in grep_paroduslogs(FWDL_PROTOCOL_MSG) + + +@pytest.mark.run(order=37) +def test_WebPA_Get_FWDL_STATUS_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadStatus"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + logs = grep_paroduslogs('Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadStatus') + assert 'Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadStatus' in logs, \ + f"FirmwareDownloadStatus parameter not found in response" + + +@pytest.mark.run(order=38) +def test_WebPA_Get_FWDL_URL_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadURL"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + FWDL_URL_MSG = '"value":"https://mockserver.tv/Images"' + assert FWDL_URL_MSG in grep_paroduslogs(FWDL_URL_MSG) + + +@pytest.mark.run(order=39) +def test_WebPA_Get_FWDL_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareToDownload"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + FWDL_MSG = '"value":"TESTIMAGE_DEV.bin"' + assert FWDL_MSG in grep_paroduslogs(FWDL_MSG) + + +@pytest.mark.run(order=40) +def test_WebPA_Get_FWUPDATE_STATUS_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareUpdateState"]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + logs = grep_paroduslogs('FirmwareUpdateState') + assert ('"value":"Download complete"' in logs or '"value":"Download Complete"' in logs), \ + f"Expected firmware update state not found. Got: {logs}" + +@pytest.mark.run(order=41) +def test_WebPA_Get_WILDCARD_STATUS_Handler(): + print("Starting parodus mock process") + payload ='{"command":"GET","names":["Device.DeviceInfo."]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + +@pytest.mark.run(order=42) +def test_WebPA_Set_FirmwareDownloadProtocol_For_Upgrade(): + print("Starting parodus mock process - Set firmware download protocol") + payload = '{"command":"SET","parameters":[{"name":"Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadProtocol","dataType":0,"value":"http"}]}' + command = ["/usr/local/bin/parodus", payload] + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + +@pytest.mark.run(order=43) +def test_WebPA_Set_FirmwareDownloadURL_For_Upgrade(): + print("Starting parodus mock process - Set firmware download URL") + payload = '{"command":"SET","parameters":[{"name":"Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadURL","dataType":0,"value":"https://mockserver.tv/Images"}]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + +@pytest.mark.run(order=44) +def test_WebPA_Set_FirmwareToDownload_For_Upgrade(): + print("Starting parodus mock process - Set firmware to download") + payload = '{"command":"SET","parameters":[{"name":"Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareToDownload","dataType":0,"value":" TESTIMAGE_DEV.bin"}]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + +@pytest.mark.run(order=45) +def test_WebPA_Set_FirmwareDownloadNow_Trigger(): + print("Starting parodus mock process - Image Upgrade via RDK portal") + payload = '{"command":"SET","parameters":[{"name":"Device.DeviceInfo.X_RDKCENTRAL-COM_FirmwareDownloadNow","dataType":3,"value":"true"}]}' + command = ["/usr/local/bin/parodus", payload] + + result = subprocess.run(command, capture_output=True, text=True) + assert result.returncode == 0, f"Command failed with error: {result.stderr}" + + STATUS_CODE_MSG = '"statusCode":200' + assert STATUS_CODE_MSG in grep_paroduslogs(STATUS_CODE_MSG) + + SUCCESS_STATUS_MSG = '"message":"Success"' + assert SUCCESS_STATUS_MSG in grep_paroduslogs(SUCCESS_STATUS_MSG) + + # Verify script was triggered in logs + sleep(3) + SCRIPT_TRIGGER_MSG = "Triggered Download" + assert SCRIPT_TRIGGER_MSG in grep_tr69hostiflogs(SCRIPT_TRIGGER_MSG) + diff --git a/tr69hostif.service b/tr69hostif.service index 5152d8775..0b6390f39 100644 --- a/tr69hostif.service +++ b/tr69hostif.service @@ -18,18 +18,18 @@ ########################################################################## [Unit] Description=TR69 Host Interface Daemon -After=lighttpd.service securemount.service dsmgr.service +After=lighttpd.service securemount.service @DSMGR_DEPENDENCY@ [Service] Type=notify SyslogIdentifier="tr69hostif" EnvironmentFile=/etc/device.properties ExecStartPre=/bin/mkdir -p /opt/tr-181 -ExecStartPre=/bin/sh -c '/lib/rdk/opt-override.sh' -ExecStart=/usr/bin/tr69hostif -c /etc/mgrlist.conf -p 10999 -s 11999 -d $DEBUGINIFILE -w $WEBPANOTIFYINCFG +ExecStart=/bin/sh -c '/usr/bin/tr69hostif -c /etc/mgrlist.conf -p 10999 -s 11999' ExecStop=/bin/kill -15 $MAINPID RestartSec=10s Restart=always +TimeoutStopSec=5 [Install] WantedBy=multi-user.target diff --git a/tr69hostif_no_new_http_server.service b/tr69hostif_no_new_http_server.service index e6b6e25a2..d78a0f3bc 100644 --- a/tr69hostif_no_new_http_server.service +++ b/tr69hostif_no_new_http_server.service @@ -26,8 +26,7 @@ Type=notify SyslogIdentifier="tr69hostif" EnvironmentFile=/etc/device.properties ExecStartPre=/bin/mkdir -p /opt/tr-181 -ExecStartPre=/bin/sh -c '/lib/rdk/opt-override.sh' -ExecStart=/usr/bin/tr69hostif -c /etc/mgrlist.conf -p 10999 -d $DEBUGINIFILE -w $WEBPANOTIFYINCFG +ExecStart=/usr/bin/tr69hostif -c /etc/mgrlist.conf -p 10999 ExecStop=/bin/kill -15 $MAINPID Restart=always