-
Notifications
You must be signed in to change notification settings - Fork 0
Gid parse fix #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+220
β15
Merged
Gid parse fix #173
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| package.path = "../src/lua-fibers/?.lua;" -- fibers submodule src | ||
| .. "../src/lua-trie/src/?.lua;" -- trie submodule src | ||
| .. "../src/lua-bus/src/?.lua;" -- bus submodule src | ||
| .. "../src/?.lua;" | ||
| .. "./test_utils/?.lua;" | ||
| .. package.path | ||
| .. ";/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua" | ||
|
|
||
| local fiber = require "fibers.fiber" | ||
| local context = require "fibers.context" | ||
|
|
||
| local function test_uim_get_gids_simple() | ||
| -- Clear cached module | ||
| package.loaded["services.hal.drivers.modem.mode.qmi"] = nil | ||
|
|
||
| -- Mock dependencies | ||
| local mock_context = { | ||
| with_timeout = function(ctx, timeout) | ||
| return ctx | ||
| end | ||
| } | ||
|
|
||
| local mock_cmd = { | ||
| setpgid_called = false, | ||
| setpgid = function(self, val) | ||
| self.setpgid_called = true | ||
| end, | ||
| combined_output = function(self) | ||
| local output = [[ | ||
| [/dev/cdc-wdm1] Successfully read information from the UIM: | ||
| Card result: | ||
| SW1: '0x90' | ||
| SW2: '0x00' | ||
| Read result: | ||
| FF]] | ||
| return output, nil | ||
| end | ||
| } | ||
|
|
||
| local mock_qmicli = { | ||
| uim_read_transparent = function(ctx, port, id) | ||
| return mock_cmd | ||
| end | ||
| } | ||
|
|
||
| local mock_wraperr = { | ||
| new = function(err) return err end | ||
| } | ||
|
|
||
| -- Load the qmi module with mocked dependencies | ||
| package.loaded["services.hal.drivers.modem.qmicli"] = mock_qmicli | ||
| package.loaded["fibers.context"] = mock_context | ||
| package.loaded["wraperr"] = mock_wraperr | ||
| package.loaded["services.hal.utils"] = require("services.hal.utils") | ||
| package.loaded["services.log"] = require("services.log") | ||
|
|
||
| local qmi_module = require("services.hal.drivers.modem.mode.qmi") | ||
|
|
||
| -- Create a mock modem object | ||
| local modem = { | ||
| ctx = context.background(), | ||
| primary_port = "/dev/cdc-wdm1" | ||
| } | ||
|
|
||
| -- Initialize the modem with qmi functions | ||
| qmi_module(modem) | ||
|
|
||
| -- Test the function | ||
| local gids, err = modem.uim_get_gids() | ||
|
|
||
| assert(err == nil, "expected err to be nil but got " .. tostring(err)) | ||
| assert(gids ~= nil, "expected gids to be a table but got nil") | ||
| assert(gids.gid1 == "FF", "expected gid1 to be 'FF' but got '" .. tostring(gids.gid1) .. "'") | ||
| assert(mock_cmd.setpgid_called, "expected setpgid to be called") | ||
| end | ||
|
|
||
| local function test_uim_get_gids_complex() | ||
| -- Clear cached module | ||
| package.loaded["services.hal.drivers.modem.mode.qmi"] = nil | ||
|
|
||
| -- Mock dependencies | ||
| local mock_context = { | ||
| with_timeout = function(ctx, timeout) | ||
| return ctx | ||
| end | ||
| } | ||
|
|
||
| local mock_cmd = { | ||
| setpgid_called = false, | ||
| setpgid = function(self, val) | ||
| self.setpgid_called = true | ||
| end, | ||
| combined_output = function(self) | ||
| local output = [[ | ||
| [/dev/cdc-wdm1] Successfully read information from the UIM: | ||
| Card result: | ||
| SW1: '0x90' | ||
| SW2: '0x00' | ||
| Read result: | ||
| 85:FF:FF:FF:FF:FF:47:45:4E:49:45:49:4E:20:20:20:20:20:20:20]] | ||
| return output, nil | ||
| end | ||
| } | ||
|
|
||
| local mock_qmicli = { | ||
| uim_read_transparent = function(ctx, port, id) | ||
| return mock_cmd | ||
| end | ||
| } | ||
|
|
||
| local mock_wraperr = { | ||
| new = function(err) return err end | ||
| } | ||
|
|
||
| -- Load the qmi module with mocked dependencies | ||
| package.loaded["services.hal.drivers.modem.qmicli"] = mock_qmicli | ||
| package.loaded["fibers.context"] = mock_context | ||
| package.loaded["wraperr"] = mock_wraperr | ||
| package.loaded["services.hal.utils"] = require("services.hal.utils") | ||
| package.loaded["services.log"] = require("services.log") | ||
|
|
||
| local qmi_module = require("services.hal.drivers.modem.mode.qmi") | ||
|
|
||
| -- Create a mock modem object | ||
| local modem = { | ||
| ctx = context.background(), | ||
| primary_port = "/dev/cdc-wdm1" | ||
| } | ||
|
|
||
| -- Initialize the modem with qmi functions | ||
| qmi_module(modem) | ||
|
|
||
| -- Test the function | ||
| local gids, err = modem.uim_get_gids() | ||
|
|
||
| assert(err == nil, "expected err to be nil but got " .. tostring(err)) | ||
| assert(gids ~= nil, "expected gids to be a table but got nil") | ||
|
|
||
| local expected = "85FFFFFFFFFF47454E4945494E20202020202020" | ||
| assert(gids.gid1 == expected, | ||
| "expected gid1 to be '" .. expected .. "' but got '" .. tostring(gids.gid1) .. "'") | ||
| assert(mock_cmd.setpgid_called, "expected setpgid to be called") | ||
| end | ||
|
|
||
| local function test_uim_get_gids_error() | ||
| -- Clear cached module | ||
| package.loaded["services.hal.drivers.modem.mode.qmi"] = nil | ||
|
|
||
| -- Mock dependencies | ||
| local mock_context = { | ||
| with_timeout = function(ctx, timeout) | ||
| return ctx | ||
| end | ||
| } | ||
|
|
||
| local mock_cmd = { | ||
| setpgid_called = false, | ||
| setpgid = function(self, val) | ||
| self.setpgid_called = true | ||
| end, | ||
| combined_output = function(self) | ||
| return "", "command failed" | ||
| end | ||
| } | ||
|
|
||
| local mock_qmicli = { | ||
| uim_read_transparent = function(ctx, port, id) | ||
| return mock_cmd | ||
| end | ||
| } | ||
|
|
||
| local mock_wraperr = { | ||
| new = function(err) return "wrapped: " .. err end | ||
| } | ||
|
|
||
| -- Load the qmi module with mocked dependencies | ||
| package.loaded["services.hal.drivers.modem.qmicli"] = mock_qmicli | ||
| package.loaded["fibers.context"] = mock_context | ||
| package.loaded["wraperr"] = mock_wraperr | ||
| package.loaded["services.hal.utils"] = require("services.hal.utils") | ||
| package.loaded["services.log"] = require("services.log") | ||
|
|
||
| local qmi_module = require("services.hal.drivers.modem.mode.qmi") | ||
|
|
||
| -- Create a mock modem object | ||
| local modem = { | ||
| ctx = context.background(), | ||
| primary_port = "/dev/cdc-wdm1" | ||
| } | ||
|
|
||
| -- Initialize the modem with qmi functions | ||
| qmi_module(modem) | ||
|
|
||
| -- Test the function | ||
| local gids, err = modem.uim_get_gids() | ||
|
|
||
| assert(err ~= nil, "expected err to be set but got nil") | ||
| assert(err == "wrapped: command failed", "expected wrapped error but got " .. tostring(err)) | ||
| assert(gids ~= nil, "expected gids to be a table but got nil") | ||
| assert(next(gids) == nil, "expected gids to be empty but it has values") | ||
| end | ||
|
|
||
| fiber.spawn(function () | ||
| test_uim_get_gids_simple() | ||
| test_uim_get_gids_complex() | ||
| test_uim_get_gids_error() | ||
| fiber.stop() | ||
| end) | ||
|
|
||
| print("running hal qmi tests") | ||
| fiber.main() | ||
| print("passed") | ||
rslater-cs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.