2013-10-25 10:51:44

by Jerzy Kasenberg

[permalink] [raw]
Subject: [PATCH v2 0/2] Add basic scripting to haltest

This patcheset adds command 'source' to interpret scripts
and processing of .haltestrc to execute some commands automatically.
v2:
- small styl changed (fd == -1) changed to (fd < 0)

Jerzy Kasenberg (2):
android/client: Add source command to haltest
android/client: Add processing of .haltestrc

android/client/haltest.c | 55 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)

--
1.7.9.5



2013-10-25 11:56:43

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH v2 0/2] Add basic scripting to haltest

Hi Jerzy,

On Fri, Oct 25, 2013 at 1:51 PM, Jerzy Kasenberg
<[email protected]> wrote:
> This patcheset adds command 'source' to interpret scripts
> and processing of .haltestrc to execute some commands automatically.
> v2:
> - small styl changed (fd == -1) changed to (fd < 0)
>
> Jerzy Kasenberg (2):
> android/client: Add source command to haltest
> android/client: Add processing of .haltestrc
>
> android/client/haltest.c | 55 +++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 54 insertions(+), 1 deletion(-)
>
> --
> 1.7.9.5

Applied, thanks.


--
Luiz Augusto von Dentz

2013-10-25 10:51:45

by Jerzy Kasenberg

[permalink] [raw]
Subject: [PATCH v2 1/2] android/client: Add source command to haltest

New command allows to read script file into tool and
execute its contents as if it was typed.
---
android/client/haltest.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index 189af0b..ac43afb 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -157,11 +157,47 @@ static void quit_p(int argc, const char **argv)
exit(0);
}

+static int fd_stack[10];
+static int fd_stack_pointer = 0;
+
+static void stdin_handler(struct pollfd *pollfd);
+
+static void process_file(const char *name)
+{
+ int fd = open(name, O_RDONLY);
+
+ if (fd < 0) {
+ haltest_error("Can't open file: %s for reading\n", name);
+ return;
+ }
+
+ if (fd_stack_pointer >= 10) {
+ haltest_error("To many open files\n");
+ close(fd);
+ return;
+ }
+
+ fd_stack[fd_stack_pointer++] = fd;
+ poll_unregister_fd(fd_stack[fd_stack_pointer - 2], stdin_handler);
+ poll_register_fd(fd_stack[fd_stack_pointer - 1], POLLIN, stdin_handler);
+}
+
+static void source_p(int argc, const char **argv)
+{
+ if (argc < 2) {
+ haltest_error("No file specified");
+ return;
+ }
+
+ process_file(argv[1]);
+}
+
/* Commands available without interface */
static struct method commands[] = {
STD_METHODCH(help, "[<interface>]"),
STD_METHOD(quit),
METHOD("exit", quit_p, NULL, NULL),
+ STD_METHODH(source, "<file>"),
END_METHOD
};

@@ -254,15 +290,26 @@ static void stdin_handler(struct pollfd *pollfd)
char buf[10];

if (pollfd->revents & POLLIN) {
- int count = read(0, buf, 10);
+ int count = read(fd_stack[fd_stack_pointer - 1], buf, 10);

if (count > 0) {
int i;

for (i = 0; i < count; ++i)
terminal_process_char(buf[i], process_line);
+ return;
}
}
+
+ if (fd_stack_pointer > 1)
+ poll_register_fd(fd_stack[fd_stack_pointer - 2], POLLIN,
+ stdin_handler);
+ if (fd_stack_pointer > 0) {
+ poll_unregister_fd(fd_stack[--fd_stack_pointer], stdin_handler);
+
+ if (fd_stack[fd_stack_pointer])
+ close(fd_stack[fd_stack_pointer]);
+ }
}

int main(int argc, char **argv)
@@ -270,6 +317,7 @@ int main(int argc, char **argv)
terminal_setup();
history_restore(".haltest_history");

+ fd_stack[fd_stack_pointer++] = 0;
/* Register command line handler */
poll_register_fd(0, POLLIN, stdin_handler);

--
1.7.9.5


2013-10-25 10:51:46

by Jerzy Kasenberg

[permalink] [raw]
Subject: [PATCH v2 2/2] android/client: Add processing of .haltestrc

This patch allows tool to read commands from .haltestrc.
So it is possible to call some functions that are typically used.
So user can have:
adapter init
adapter get_profile_interface socket
adapter get_profile_interface pan
adapter get_profile_interface hidhost
adapter get_profile_interface a2dp
pan init
av init
---
android/client/haltest.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index ac43afb..6b4030b 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -314,6 +314,8 @@ static void stdin_handler(struct pollfd *pollfd)

int main(int argc, char **argv)
{
+ struct stat rcstat;
+
terminal_setup();
history_restore(".haltest_history");

@@ -321,6 +323,9 @@ int main(int argc, char **argv)
/* Register command line handler */
poll_register_fd(0, POLLIN, stdin_handler);

+ if (stat(".haltestrc", &rcstat) == 0 && (rcstat.st_mode & S_IFREG) != 0)
+ process_file(".haltestrc");
+
poll_dispatch_loop();

return 0;
--
1.7.9.5