aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Richter <stefanr@s5r6.in-berlin.de>2008-12-07 14:24:56 +0100
committerDan Dennedy <dan@dennedy.org>2008-12-07 23:09:09 -0800
commitb63022aeeb7430186d4659fcfe73070a3806df8e (patch)
tree63a447db1c9338950d3c914cf8a49a7ce5c17828
parent4904ff698d4187b49b960ff54bd714ee81893ba8 (diff)
downloadlibraw1394-b63022aeeb7430186d4659fcfe73070a3806df8e.tar.gz
testlibraw: test all cards instead of only the first
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> Signed-off-by: Dan Dennedy <dan@dennedy.org>
-rw-r--r--tools/testlibraw.c263
1 files changed, 143 insertions, 120 deletions
diff --git a/tools/testlibraw.c b/tools/testlibraw.c
index 1064a38..9b31a3a 100644
--- a/tools/testlibraw.c
+++ b/tools/testlibraw.c
@@ -53,8 +53,8 @@ static const unsigned char fcp_data[] =
int my_fcp_handler(raw1394handle_t handle, nodeid_t nodeid, int response,
size_t length, unsigned char *data)
{
- printf("got fcp %s from node %d of %d bytes:",
- (response ? "response" : "command"), nodeid & 0x3f, length);
+ printf(" got fcp %s from node %d of %d bytes:",
+ (response ? "response" : "command"), nodeid & 0x3f, length);
if (memcmp(fcp_data, data, sizeof fcp_data) != 0)
printf("ERROR: fcp payload not correct\n");
@@ -73,7 +73,7 @@ int my_fcp_handler(raw1394handle_t handle, nodeid_t nodeid, int response,
static void
test_fcp(raw1394handle_t handle)
{
- printf("\ntesting FCP monitoring on local node\n");
+ printf("\n - testing FCP monitoring on local node\n");
raw1394_set_fcp_handler(handle, my_fcp_handler);
raw1394_start_fcp_listen(handle);
raw1394_write(handle, raw1394_get_local_id(handle),
@@ -95,143 +95,166 @@ read_topology_map(raw1394handle_t handle)
retval = raw1394_read(handle, local_id,
CSR_REGISTER_BASE + CSR_TOPOLOGY_MAP, 12, &map[0]);
- if (retval < 0)
- perror("topology map: raw1394_read failed with error");
-
+ if (retval < 0) {
+ perror("\n - topology map: raw1394_read failed with error");
+ return;
+ }
+
self_id_count = ntohl(map[2]) & 0xffff;
node_count = ntohl(map[2]) >> 16;
retval = raw1394_read(handle, local_id,
CSR_REGISTER_BASE + CSR_TOPOLOGY_MAP + 12,
self_id_count * sizeof map[0], &map[3]);
- if (retval < 0)
- perror("topology map: raw1394_read failed with error");
+ if (retval < 0) {
+ perror("\n - topology map: raw1394_read failed with error");
+ return;
+ }
- printf("topology map: %d nodes, %d self ids, generation %d\n",
+ printf("\n - topology map: %d nodes, %d self ids, generation %d\n",
node_count, self_id_count, ntohl(map[1]));
for (i = 0; i < self_id_count; i++)
- printf(" 0x%08x\n", ntohl(map[3 + i]));
+ printf(" 0x%08x\n", ntohl(map[3 + i]));
}
-int main(int argc, char **argv)
+static void
+test_config_rom(raw1394handle_t handle)
{
- raw1394handle_t handle;
- int i, numcards;
- struct raw1394_portinfo pinf[16];
-
- tag_handler_t std_handler;
- int retval;
-
- struct pollfd pfd;
- quadlet_t rom[0x100];
- size_t rom_size;
- unsigned char rom_version;
-
- handle = raw1394_new_handle();
-
- if (!handle) {
- if (!errno) {
- printf(not_compatible);
- } else {
- perror("couldn't get handle");
- printf(not_loaded);
- }
- exit(1);
- }
-
- printf("successfully got handle\n");
- printf("current generation number: %d\n", raw1394_get_generation(handle));
-
- numcards = raw1394_get_port_info(handle, pinf, 16);
- if (numcards < 0) {
- perror("couldn't get card info");
- exit(1);
- } else {
- printf("%d card(s) found\n", numcards);
- }
-
- if (!numcards) {
- exit(0);
- }
-
- for (i = 0; i < numcards; i++) {
- printf(" nodes on bus: %2d, card name: %s\n", pinf[i].nodes,
- pinf[i].name);
- }
-
- if (raw1394_set_port(handle, 0) < 0) {
- perror("couldn't set port");
- exit(1);
- }
+ quadlet_t rom[0x100] = { 0, };
+ size_t rom_size;
+ unsigned char rom_version;
+ int i, retval;
+
+ printf("\n - testing config rom\n");
+ retval = raw1394_get_config_rom(handle, rom, 0x100,
+ &rom_size, &rom_version);
+ printf(" get_config_rom returned %d, romsize %d, rom_version %d\n",
+ retval, rom_size, rom_version);
+ printf(" here are the first 10 quadlets:\n");
+ for (i = 0; i < 10; i++)
+ printf(" 0x%08x\n", i, rom[i]);
+
+ retval = raw1394_update_config_rom(handle, rom, rom_size, rom_version);
+ printf(" update_config_rom returned %d\n", retval);
+}
- printf("using first card found: %d nodes on bus, local ID is %d, IRM is %d\n",
- raw1394_get_nodecount(handle),
- raw1394_get_local_id(handle) & 0x3f,
- raw1394_get_irm_id(handle) & 0x3f);
-
- printf("\ndoing transactions with custom tag handler\n");
- std_handler = raw1394_set_tag_handler(handle, my_tag_handler);
- for (i = 0; i < pinf[0].nodes; i++) {
- printf("trying to send read request to node %d... ", i);
- fflush(stdout);
- buffer = 0;
-
- if (raw1394_start_read(handle, 0xffc0 | i, TESTADDR, 4,
- &buffer, 0) < 0) {
- perror("failed");
- continue;
- }
- if (raw1394_loop_iterate(handle))
+int test_card(int card)
+{
+ raw1394handle_t handle;
+ struct raw1394_portinfo pinf;
+ tag_handler_t std_handler;
+ struct pollfd pfd;
+ int i, n, numcards, retval;
+
+ handle = raw1394_new_handle();
+
+ if (!handle) {
+ if (!errno) {
+ printf(not_compatible);
+ } else {
+ perror("couldn't get handle");
+ printf(not_loaded);
+ }
+ return -1;
+ }
+
+ if (card == 0) {
+ printf("successfully got handle\n");
+ printf("current generation number: %d\n",
+ raw1394_get_generation(handle));
+ }
+
+ numcards = raw1394_get_port_info(handle, &pinf, 1);
+ if (numcards < card)
+ perror("couldn't get card info");
+ else if (card == 0)
+ printf("%d card%s found\n",
+ numcards, numcards == 1 ? "" : "s");
+
+ if (numcards <= card)
+ goto out;
+
+ printf("\ncard %d, name: %s\n", card, pinf.name);
+
+ if (raw1394_set_port(handle, card) < 0) {
+ perror("couldn't set port");
+ goto out;
+ }
+
+ n = raw1394_get_nodecount(handle);
+ printf("%d nodes on bus, local ID is %d, IRM is %d\n",
+ n,
+ raw1394_get_local_id(handle) & 0x3f,
+ raw1394_get_irm_id(handle) & 0x3f);
+
+ if (n > 0) {
+ printf("\n - doing transactions with custom tag handler\n");
+ std_handler = raw1394_set_tag_handler(handle, my_tag_handler);
+ }
+ for (i = 0; i < n; i++) {
+ printf(" read from node %d... ", i);
+ fflush(stdout);
+ buffer = 0;
+
+ if (raw1394_start_read(handle, 0xffc0 | i, TESTADDR, 4,
+ &buffer, 0) < 0) {
perror("failed");
- }
-
- printf("\nusing standard tag handler and synchronous calls\n");
- raw1394_set_tag_handler(handle, std_handler);
- for (i = 0; i < pinf[0].nodes; i++) {
- printf("trying to read from node %d... ", i);
- fflush(stdout);
- buffer = 0;
-
- retval = raw1394_read(handle, 0xffc0 | i, TESTADDR, 4, &buffer);
- if (retval < 0) {
- perror("failed with error");
- } else {
- printf("completed with value 0x%08x\n", buffer);
- }
- }
+ continue;
+ }
+ if (raw1394_loop_iterate(handle))
+ perror("failed");
+ }
+
+ if (n > 0) {
+ printf("\n - using standard tag handler and synchronous calls\n");
+ raw1394_set_tag_handler(handle, std_handler);
+ }
+ for (i = 0; i < n; i++) {
+ printf(" read from node %d... ", i);
+ fflush(stdout);
+ buffer = 0;
+
+ retval = raw1394_read(handle, 0xffc0 | i, TESTADDR, 4, &buffer);
+ if (retval < 0)
+ perror("failed with error");
+ else
+ printf("completed with value 0x%08x\n", buffer);
+ }
test_fcp(handle);
read_topology_map(handle);
+ test_config_rom(handle);
- printf("testing config rom stuff\n");
- memset(rom, 0, sizeof(rom));
- retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version);
- printf("get_config_rom returned %d, romsize %d, rom_version %d\n",retval,rom_size,rom_version);
- printf("here are the first 10 quadlets:\n");
- for (i = 0; i < 10; i++)
- printf("%d. quadlet: 0x%08x\n",i,rom[i]);
-
- /* some manipulation */
-/* printf("incrementing 2nd quadlet\n");
- rom[0x02/4]++;
-*/
- retval=raw1394_update_config_rom(handle, rom, rom_size, rom_version);
- printf("update_config_rom returned %d\n",retval);
-
- printf("\nposting 0xdeadbeef as an echo request\n");
+ printf("\n - posting 0xdeadbeef as an echo request\n");
raw1394_echo_request(handle, 0xdeadbeef);
- printf("polling for leftover messages\n");
- pfd.fd = raw1394_get_fd(handle);
- pfd.events = POLLIN;
- pfd.revents = 0;
- while (1) {
- retval = poll(&pfd, 1, 10);
- if (retval < 1) break;
+ printf(" polling for leftover messages\n");
+ pfd.fd = raw1394_get_fd(handle);
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+ while (1) {
+ retval = poll(&pfd, 1, 10);
+ if (retval < 1)
+ break;
retval = raw1394_loop_iterate(handle);
if (retval != 0)
- printf("raw1394_loop_iterate() returned 0x%08x\n", retval);
- }
+ printf(" raw1394_loop_iterate() returned 0x%08x\n",
+ retval);
+ }
+
+ if (retval < 0)
+ perror("poll failed");
+out:
+ raw1394_destroy_handle(handle);
+ return numcards;
+}
+
+int main(int argc, char **argv)
+{
+ int card = 0, numcards;
+
+ do
+ numcards = test_card(card);
+ while (++card < numcards);
- if (retval < 0) perror("poll failed");
- exit(0);
+ return numcards < 0;
}