public void testingGDBBuffer() { GDBParserUnitTests.clean_Buffers(); Assert.AreEqual(false, GDBParserUnitTests.add_Into_GDB_Buffer(-1, -1, "resp_-1"), "It added resp_-1 in position -1 of Output Buffer! That should not be possible!"); Assert.AreEqual(false, GDBParserUnitTests.add_Into_GDB_Buffer(-6, -6, "resp_-6"), "It added resp_-6 in position -6 of Output Buffer! That should not be possible!"); Assert.AreEqual(true, GDBParserUnitTests.add_Into_GDB_Buffer(173, 173, "resp_" + 173), "Could not add resp_" + 173 + " in position " + 73 + " of Output Buffer."); Assert.AreEqual(true, GDBParserUnitTests.add_Into_GDB_Buffer(2314, 2314, "resp_" + 2314), "Could not add resp_" + 2314 + " in position " + 14 + " of Output Buffer."); Assert.AreEqual(false, GDBParserUnitTests.add_Into_GDB_Buffer(714, 714, "resp_" + 714), "Could not add resp_" + 714 + " in position " + 14 + " of Output Buffer."); string param = ""; Assert.AreEqual(-7, GDBParserUnitTests.remove_From_GDB_Buffer(-7, out param)); StringAssert.AreEqualIgnoringCase("", param, "-7"); param = ""; Assert.AreEqual(173, GDBParserUnitTests.remove_From_GDB_Buffer(73, out param)); StringAssert.AreEqualIgnoringCase("resp_173", param, "73"); param = ""; Assert.AreEqual(2314, GDBParserUnitTests.remove_From_GDB_Buffer(14, out param)); StringAssert.AreEqualIgnoringCase("resp_2314", param, "14"); GDBParserUnitTests.clean_Buffers(); Assert.AreEqual(true, GDBParserUnitTests.is_GDB_Buffer_Empty(), "GDB buffer should be empty. (1)"); for (int i = 0; i < 100; i++) { Assert.AreEqual(true, GDBParserUnitTests.add_Into_GDB_Buffer(i, i, "param_" + i), "Could not add seq_id=" + i + "; instruction code=" + i + "; param=param_" + i + " in GDB Buffer."); } Assert.AreEqual(false, GDBParserUnitTests.add_Into_GDB_Buffer(16, 16, "param_" + 16), "Could not add seq_id=" + 16 + "; instruction code=" + 16 + "; param=param_" + 16 + " in GDB Buffer."); Assert.AreEqual(false, GDBParserUnitTests.is_GDB_Buffer_Empty(), "GDB buffer should not be empty."); for (int i = 0; i < 100; i++) { param = ""; Assert.AreEqual(i, GDBParserUnitTests.remove_From_GDB_Buffer(i, out param)); StringAssert.AreEqualIgnoringCase("param_" + i, param, "" + i); } Assert.AreEqual(true, GDBParserUnitTests.is_GDB_Buffer_Empty(), "GDB buffer should be empty. (2)"); Assert.AreEqual(true, GDBParserUnitTests.add_Into_GDB_Buffer(21, 21, "param_21"), "Could not add lastCmd in GDB Buffer."); Assert.AreEqual(false, GDBParserUnitTests.is_GDB_Buffer_Empty(), "GDB buffer should not be empty. (3)"); GDBParserUnitTests.clean_Buffers(); Assert.AreEqual(true, GDBParserUnitTests.is_GDB_Buffer_Empty(), "GDB buffer should be empty. (4)"); }
public void testingInputBuffer() { GDBParserUnitTests.clean_Buffers(); Assert.AreEqual(true, GDBParser.is_Input_Buffer_Empty(), "Input buffer should be empty."); for (int i = 0; i < 49; i++) { Assert.AreEqual(true, GDBParserUnitTests.add_Into_Input_Buffer("cmd_" + i), "Could not add cmd_" + i + " in Input Buffer."); } Assert.AreEqual(false, GDBParser.is_Input_Buffer_Empty(), "Input buffer should not be empty."); // to be sure that the Input buffer is circular, it is being deleted 20 elements and then adding them again. for (int i = 0; i < 20; i++) { string input = GDBParserUnitTests.remove_From_Input_Buffer(); StringAssert.AreNotEqualIgnoringCase("", input, "" + i); } for (int i = 0; i < 20; i++) { Assert.AreEqual(true, GDBParserUnitTests.add_Into_Input_Buffer("cmd_" + i), "Could not add cmd_" + i + " in Input Buffer."); } for (int i = 0; i < 49; i++) { string input = GDBParserUnitTests.remove_From_Input_Buffer(); StringAssert.AreNotEqualIgnoringCase("", input, "" + i); } Assert.AreEqual(true, GDBParser.is_Input_Buffer_Empty(), "Input buffer should be empty."); Assert.AreEqual(true, GDBParserUnitTests.add_Into_Input_Buffer("lastCmd"), "Could not add lastCmd in Input Buffer."); Assert.AreEqual(false, GDBParser.is_Input_Buffer_Empty(), "Input buffer should not be empty."); GDBParserUnitTests.clean_Buffers(); Assert.AreEqual(true, GDBParser.is_Input_Buffer_Empty(), "Input buffer should be empty."); }
public void testingOutputBuffer() { GDBParserUnitTests.clean_Buffers(); Assert.AreEqual(false, GDBParserUnitTests.add_Into_Output_Buffer(-1, "resp_-1"), "It added resp_-1 in position -1 of Output Buffer! That should not be possible!"); Assert.AreEqual(false, GDBParserUnitTests.add_Into_Output_Buffer(-6, "resp_-6"), "It added resp_-6 in position -6 of Output Buffer! That should not be possible!"); Assert.AreEqual(true, GDBParserUnitTests.add_Into_Output_Buffer(173, "resp_" + 173), "Could not add resp_" + 173 + " in position " + 73 + " of Output Buffer."); Assert.AreEqual(true, GDBParserUnitTests.add_Into_Output_Buffer(2314, "resp_" + 2314), "Could not add resp_" + 2314 + " in position " + 14 + " of Output Buffer."); Assert.AreEqual(false, GDBParserUnitTests.add_Into_Output_Buffer(714, "resp_" + 714), "Could not add resp_" + 714 + " in position " + 14 + " of Output Buffer."); string output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(-3); StringAssert.AreEqualIgnoringCase("", output, "-3"); output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(73); StringAssert.AreEqualIgnoringCase("", output, "73"); output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(14); StringAssert.AreNotEqualIgnoringCase("", output, "14"); GDBParserUnitTests.clean_Buffers(); for (int i = 0; i < 100; i++) { Assert.AreEqual(true, GDBParserUnitTests.add_Into_Output_Buffer(i, "resp_" + i), "Could not add resp_" + i + " in position " + i + " of Output Buffer."); } // testing the circular part of Output buffer, by deleting 20 elements and then adding them again. for (int i = 0; i < 20; i++) { output = GDBParserUnitTests.remove_From_Output_Buffer(); StringAssert.AreNotEqualIgnoringCase("", output, "" + i); } // The circular part of Output buffer starts in position 50. for (int i = 50; i < 70; i++) { Assert.AreEqual(true, GDBParserUnitTests.add_Into_Output_Buffer(i, "resp_" + i), "Could not add resp_" + i + " in position " + i + " of Output Buffer."); } for (int i = 0; i < 50; i++) { output = GDBParserUnitTests.remove_From_Output_Buffer(); StringAssert.AreNotEqualIgnoringCase("", output, "" + i); } // testing the first 50 positions of Output buffer, the "Synchronous" part. Deleting 20 elements and adding them again. for (int i = 0; i < 20; i++) { output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(i); StringAssert.AreNotEqualIgnoringCase("", output, "" + i); } // The circular part of Output buffer starts in position 50. for (int i = 0; i < 20; i++) { Assert.AreEqual(true, GDBParserUnitTests.add_Into_Output_Buffer(i, "resp_" + i), "Could not add resp_" + i + " in position " + i + " of Output Buffer."); } for (int i = 0; i < 50; i++) { output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(i); StringAssert.AreNotEqualIgnoringCase("", output, "" + i); } string asyncInst = "??=thread-exited,id;{#51\\;;??\";@@\";#$EOL$;};??thread-created,id;{#40\\;;??\";@@\";#\\;;??pid ;@@ ;#$EOL$;};0;??*running;{#41\\;;??thread-id=\"all;{#0;}{??thread-id=\";@@\";};#$EOL$;};0;??*stopped;{??breakpoint-hit;{#27\\;;??bkptno=\";@@\";#\\;;??file=\";@@\";#\\;;??line=\";@@\";}{??end-stepping-range;{#45;??file=\";{#\\;;@@\";0;#\\;;??line=\";@@\";};}{??function-finished;{#46;??file=;{#\\;;??\";@@\";#\\;;??line=\";@@\";};}{??exited-normally;{#42;}{??exit-code;{#43\\;;??\";@@\";}{??signal-received;{??signal-meaning=\"Killed\";{#47;}{??signal-meaning=\"Segmentation fault\";{#54\\;;??addr=\";@@\";#\\;;??func=\";@@\";0;??file=;{#\\;;??\";@@\";#\\;;??line=\";@@\";};}{#44\\;;??addr=\";@@\";#\\;;??func=\";@@\";0;??file=;{#\\;;??\";@@\";#\\;;??line=\";@@\";};};};}{??exited-signalled;{#55\\;??signal-name=\";@@\";#\\;;??signal-meaning=\";@@\";}{#44\\;;??addr=\";@@\";#\\;;??func=\";@@\";0;??file=;{#\\;;??\";@@\";#\\;;??line=\";@@\";};};};};};};};};#\\;;??thread-id=;{??\";@@\";};#$EOL$;};0;??=breakpoint-modified,bkpt=\\{number=\";{0;($EOR$;$1=?<?=breakpoint-modified,bkpt=\\{number=\";@@\";$$;$EOR$;?<?=breakpoint-modified,bkpt=\\{number=\"$1$;#21\\;$1$\\;;??enabled=\";@@\";#\\;;??addr=\";@@\";#\\;;??func=\";@@\";#\\;;??file=\";@@\";#\\;;??line=\";@@\";#\\;;??times=\";@@\";0;(??=breakpoint-modified,bkpt=\\{number=\"$1$;%?<?$EOL$;@@\"\\};);):$EOL$;};0;??=breakpoint-deleted,id=;{0;(??=breakpoint-deleted,id=\";#22\\;;@@\";):$EOL$;};0;??@\";{0;#81\\;\";(??@\";?<?@;@@$EOL$;):$EOL$;#\"!81$EOL$;};0;(??~\";#80\\;\";?<?~;@@$EOL$;#\"!80;):$EOL$;??Error in testing breakpoint condition;{#29\\;$EOL$;};??Quit (expect signal SIGINT when the program is resumed);{#50\\;$EOL$;};??2374: internal-error: frame_cleanup_after_sniffer: Assertion;{#52\\;$EOL$;};??^error,msg=\"Remote communication error: No error.;{#53\\;$EOL$;};??: internal-error: handle_inferior_event: Assertion;{#56\\;$EOL$;};0;(??&\";#80\\;\";?<?&;@@$EOL$;#\"!80;):$EOL$;(??$EOL$=;#80\\;\";?<?=;@@$EOL$;#\"!80;):$EOL$;"; // Add the values you want to test. GDBParserUnitTests.parse_GDB("12^done;1\r\n", "??^done;{#23;@@$EOL$};", 5); output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(5); StringAssert.AreEqualIgnoringCase("23;1", output, "23;1" + 5); output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(5); StringAssert.AreEqualIgnoringCase("", output, "" + 5); GDBParserUnitTests.parse_GDB("4^done;1;100\r\n", "??^done;{#26;@@$EOL$};", 45); output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(45); StringAssert.AreEqualIgnoringCase("26;1;100", output, "26;1;100" + 45); // to reset the out_OutputBuffer pointer, that points to the next position from the circular part of Output Buffer to be taken. GDBParserUnitTests.clean_Buffers(); // Parsing some samples of GDB responses and adding the results in the Output Buffer. GDBParserUnitTests.parse_GDB("73^done,bkpt={number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"0x08048564\",func=\"main\",file=\"myprog.c\",fullname=\"/home/nickrob/myprog.c\",line=\"68\",thread-groups=[\"i1\"],times=\"0\"}", "??^done;{#20\\;;??number=\";{@@\";};#\\;;??enabled=\";{@@\";};#\\;;??addr=\";{@@\";};#\\;;??func=\";{@@\";};#\\;;??file=\";{@@\";};#\\;;??line=\";{@@\";};#\\;;??times=\";{@@\";};}{#Function not found!;};", 51); GDBParserUnitTests.parse_GDB("*stopped,reason=\"breakpoint-hit\",disp=\"keep\",bkptno=\"1\",thread-id=\"0\",frame={addr=\"0x08048564\",func=\"main\",args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\"0xbfc4d4d4\"}],file=\"myprog.c\",fullname=\"/home/nickrob/myprog.c\",line=\"68\"}", asyncInst, 53); GDBParserUnitTests.parse_GDB("*stopped,reason=\"exited-normally\"", asyncInst, 52); GDBParserUnitTests.parse_GDB("*stopped,reason=\"end-stepping-range\",thread-id=\"2\",line=\"187\",file=\"../../../devo/gdb/testsuite/gdb.threads/linux-dp.c\"", asyncInst, 36); GDBParserUnitTests.parse_GDB("*stopped,reason=\"function-finished\",frame={func=\"main\",args=[],file=\"hello.c\",fullname=\"/home/foo/bar/hello.c\",line=\"7\"}", asyncInst, 50); GDBParserUnitTests.parse_GDB("111*stopped,signal-name=\"SIGINT\",signal-meaning=\"Interrupt\",frame={addr=\"0x00010140\",func=\"foo\",args=[],file=\"try.c\",fullname=\"/home/foo/bar/try.c\",line=\"13\"}", asyncInst, 23); // Getting the parsed responses from the synchronous part of Output buffer output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(23); StringAssert.AreEqualIgnoringCase("44;0x00010140;foo;try.c;13;\r\n", output, "44;0x00010140;foo;try.c;13;\r\n" + 23); output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(36); StringAssert.AreEqualIgnoringCase("45;../../../devo/gdb/testsuite/gdb.threads/linux-dp.c;187;\r\n", output, "45;../../../devo/gdb/testsuite/gdb.threads/linux-dp.c;187;\r\n" + 86); // Getting the parsed responses from the circular part of Output Buffer for (int i = 50; i < 100; i++) { output = GDBParserUnitTests.remove_From_Output_Buffer(); switch (i) { case 50: StringAssert.AreEqualIgnoringCase("46;hello.c;7;\r\n", output, "46;hello.c;7;\r\n" + 50); break; case 51: StringAssert.AreEqualIgnoringCase("20;1;y;0x08048564;main;myprog.c;68;0", output, "20;1;y;0x08048564;main;myprog.c;68;0" + 51); break; case 52: StringAssert.AreEqualIgnoringCase("42;\r\n", output, "42;\r\n" + 52); break; case 53: StringAssert.AreEqualIgnoringCase("27;1;myprog.c;68;\r\n", output, "27;1;myprog.c;68;\r\n" + 53); break; default: StringAssert.AreEqualIgnoringCase("", output, "" + i); break; } } GDBParserUnitTests.parse_GDB("", "", 5); output = GDBParserUnitTests.remove_Sync_From_Output_Buffer(5); // parse_GDB changes an empty parsed response from GDB to "$#@EMPTY@#$", so the method that is waiting for this parsed response // knows that the response was really parsed and returned an empty string. StringAssert.AreEqualIgnoringCase("$#@EMPTY@#$", output, "$#@EMPTY@#$" + 5); }