| … | … | @@ -94,7 +94,7 @@ public: |
| 94 | 94 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 95 | 95 | |
| 96 | 96 | // Test basic JSON shell interaction |
| 97 | std::string cmd = "echo 'json\n.\n' | nc -q 1 localhost " + std::to_string(port); | |
| 97 | std::string cmd = "printf 'json\\n.\\n' | nc -q 1 localhost " + std::to_string(port); | |
| 98 | 98 | int rc = system(cmd.c_str()); |
| 99 | 99 | TS_ASSERT_EQUALS(rc, 0); |
| 100 | 100 | |
| … | … | @@ -107,7 +107,7 @@ public: |
| 107 | 107 | |
| 108 | 108 | // Test JSON query functionality with AtomSpace.version() using netcat |
| 109 | 109 | std::string result = json_cmd_exec( |
| 110 | "echo 'json\\nAtomSpace.version()\\n' | nc -q 1 localhost 17335"); | |
| 110 | "printf 'json\\nAtomSpace.version()\\n' | nc -q 1 localhost 17335"); | |
| 111 | 111 | |
| 112 | 112 | // The reply should contain a version number |
| 113 | 113 | TS_ASSERT(result.size() > 0); |
| … | … | @@ -122,7 +122,7 @@ public: |
| 122 | 122 | |
| 123 | 123 | // Test JSON shell evaluation via netcat |
| 124 | 124 | std::string result = json_cmd_exec( |
| 125 | "echo 'json\\nAtomSpace.version()\\n' | nc -q 1 localhost 17335"); | |
| 125 | "printf 'json\\nAtomSpace.version()\\n' | nc -q 1 localhost 17335"); | |
| 126 | 126 | |
| 127 | 127 | TS_ASSERT(result.size() > 0); |
| 128 | 128 | // The version should be a numeric string with a dot |
| … | … | @@ -136,13 +136,13 @@ public: |
| 136 | 136 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 137 | 137 | |
| 138 | 138 | // First, add an atom using the Scheme shell |
| 139 | int rc = system("echo '(Concept \"test-concept-json\")' | nc -q 1 localhost 17335"); | |
| 139 | int rc = system("printf '(Concept \"test-concept-json\")\\n' | nc -q 1 localhost 17335"); | |
| 140 | 140 | TS_ASSERT_EQUALS(rc, 0); |
| 141 | 141 | usleep(50000); |
| 142 | 142 | |
| 143 | 143 | // Test JSON shell can access the atom |
| 144 | 144 | std::string result = json_cmd_exec( |
| 145 | "echo 'json\\nAtomSpace.haveNode(\"Concept\", \"test-concept-json\")\\n' | nc -q 1 localhost 17335"); | |
| 145 | "printf 'json\\nAtomSpace.haveNode(\"Concept\", \"test-concept-json\")\\n' | nc -q 1 localhost 17335"); | |
| 146 | 146 | |
| 147 | 147 | printf("Do we have the node? result=>>>%s<<<\n", result.c_str()); |
| 148 | 148 | // Should return "true" |
| … | … | @@ -156,20 +156,20 @@ public: |
| 156 | 156 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 157 | 157 | |
| 158 | 158 | // Add some atoms using the Scheme shell |
| 159 | int rc = system("echo '(Concept \"json-test-1\")' | nc -q 1 localhost 17335"); | |
| 159 | int rc = system("printf '(Concept \"json-test-1\")\\n' | nc -q 1 localhost 17335"); | |
| 160 | 160 | TS_ASSERT_EQUALS(rc, 0); |
| 161 | 161 | usleep(50000); |
| 162 | rc = system("echo '(Concept \"json-test-2\")' | nc -q 1 localhost 17335"); | |
| 162 | rc = system("printf '(Concept \"json-test-2\")\\n' | nc -q 1 localhost 17335"); | |
| 163 | 163 | TS_ASSERT_EQUALS(rc, 0); |
| 164 | 164 | usleep(50000); |
| 165 | rc = system("echo '(Number 42)' | nc -q 1 localhost 17335"); | |
| 165 | rc = system("printf '(Number 42)\\n' | nc -q 1 localhost 17335"); | |
| 166 | 166 | TS_ASSERT_EQUALS(rc, 0); |
| 167 | 167 | usleep(50000); |
| 168 | 168 | |
| 169 | 169 | // Get all ConceptNodes via JSON shell |
| 170 | 170 | // -q3 because the guix test environment is slow as molasses |
| 171 | 171 | std::string result = json_cmd_exec( |
| 172 | "echo 'json\\nAtomSpace.getAtoms(\"ConceptNode\")\\n' | nc -q 3 localhost 17335"); | |
| 172 | "printf 'json\\nAtomSpace.getAtoms(\"ConceptNode\")\\n' | nc -q 3 localhost 17335"); | |
| 173 | 173 | |
| 174 | 174 | printf("Did we get the Concepts? result=>>>%s<<<\n", result.c_str()); |
| 175 | 175 | TS_ASSERT(result.find("json-test-1") != std::string::npos); |
| … | … | @@ -185,14 +185,14 @@ public: |
| 185 | 185 | // Create a new atom via JSON command |
| 186 | 186 | // -q3 because the guix test environment is slow as molasses |
| 187 | 187 | std::string result = json_cmd_exec( |
| 188 | "echo 'json\\nAtomSpace.makeAtom({\"type\": \"Concept\", \"name\": \"json-created\"})\\n' | nc -q 3 localhost 17335"); | |
| 188 | "printf 'json\\nAtomSpace.makeAtom({\"type\": \"Concept\", \"name\": \"json-created\"})\\n' | nc -q 3 localhost 17335"); | |
| 189 | 189 | |
| 190 | 190 | printf("Did we make the Concept? result=>>>%s<<<\n", result.c_str()); |
| 191 | 191 | TS_ASSERT(result.find("true") != std::string::npos); |
| 192 | 192 | |
| 193 | 193 | // Verify the atom was created by checking with haveNode |
| 194 | 194 | std::string verify = json_cmd_exec( |
| 195 | "echo 'json\\nAtomSpace.haveNode(\"Concept\", \"json-created\")\\n' | nc -q 3 localhost 17335"); | |
| 195 | "printf 'json\\nAtomSpace.haveNode(\"Concept\", \"json-created\")\\n' | nc -q 3 localhost 17335"); | |
| 196 | 196 | |
| 197 | 197 | printf("Did verification work? verify=>>>%s<<<\n", result.c_str()); |
| 198 | 198 | TS_ASSERT(verify.find("true") != std::string::npos); |
| … | … | @@ -94,7 +94,7 @@ public: |
| 94 | 94 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 95 | 95 | |
| 96 | 96 | // Test basic MCP shell connection |
| 97 | int rc = system("echo 'mcp\n.\n' | nc -q 1 localhost 17334"); | |
| 97 | int rc = system("printf 'mcp\\n.\\n' | nc -q 1 localhost 17334"); | |
| 98 | 98 | TS_ASSERT_EQUALS(rc, 0); |
| 99 | 99 | |
| 100 | 100 | logger().debug("END TEST: %s", __FUNCTION__); |
| … | … | @@ -106,7 +106,7 @@ public: |
| 106 | 106 | |
| 107 | 107 | // Test MCP shell in server mode |
| 108 | 108 | std::string reply = mcp_cmd_exec( |
| 109 | "echo 'mcp server localhost 8081\n.\n' | nc -q 1 localhost 17334"); | |
| 109 | "printf 'mcp server localhost 8081\\n.\\n' | nc -q 1 localhost 17334"); | |
| 110 | 110 | |
| 111 | 111 | TS_ASSERT(reply.size() > 0); |
| 112 | 112 | TS_ASSERT(reply.find("MCP shell") != std::string::npos); |
| … | … | @@ -120,7 +120,7 @@ public: |
| 120 | 120 | |
| 121 | 121 | // Test MCP shell in client mode |
| 122 | 122 | std::string reply = mcp_cmd_exec( |
| 123 | "echo 'mcp client\n.\n' | nc -q 1 localhost 17334"); | |
| 123 | "printf 'mcp client\\n.\\n' | nc -q 1 localhost 17334"); | |
| 124 | 124 | |
| 125 | 125 | TS_ASSERT(reply.size() > 0); |
| 126 | 126 | TS_ASSERT(reply.find("MCP shell") != std::string::npos); |
| … | … | @@ -134,7 +134,7 @@ public: |
| 134 | 134 | |
| 135 | 135 | // Test MCP shell with hush mode |
| 136 | 136 | std::string reply = mcp_cmd_exec( |
| 137 | "echo 'mcp hush\n' | nc -q 1 localhost 17334"); | |
| 137 | "printf 'mcp hush\\n' | nc -q 1 localhost 17334"); | |
| 138 | 138 | |
| 139 | 139 | // Hush mode should return minimal output |
| 140 | 140 | TS_ASSERT(reply.size() < 100); |
| … | … | @@ -148,7 +148,7 @@ public: |
| 148 | 148 | |
| 149 | 149 | // Test MCP ping via the shell using netcat |
| 150 | 150 | std::string result = mcp_cmd_exec( |
| 151 | "echo 'mcp\\n{\"jsonrpc\":\"2.0\",\"method\":\"ping\",\"id\":1}\\n' | nc -q 1 localhost 17334"); | |
| 151 | "printf 'mcp\\n{\"jsonrpc\":\"2.0\",\"method\":\"ping\",\"id\":1}\\n' | nc -q 1 localhost 17334"); | |
| 152 | 152 | |
| 153 | 153 | TS_ASSERT(result.size() > 0); |
| 154 | 154 | // Verify it's a valid JSON-RPC response |
| … | … | @@ -164,7 +164,7 @@ public: |
| 164 | 164 | |
| 165 | 165 | // Test tools/list via the MCP shell using netcat |
| 166 | 166 | std::string reply_str = mcp_cmd_exec( |
| 167 | "echo 'mcp\\n{\"jsonrpc\":\"2.0\",\"method\":\"tools/list\",\"id\":1}\\n' | nc -q 1 localhost 17334"); | |
| 167 | "printf 'mcp\\n{\"jsonrpc\":\"2.0\",\"method\":\"tools/list\",\"id\":1}\\n' | nc -q 1 localhost 17334"); | |
| 168 | 168 | |
| 169 | 169 | // Verify the reply contains a valid JSON-RPC response |
| 170 | 170 | TS_ASSERT(reply_str.find("{") != std::string::npos); |
| … | … | @@ -181,14 +181,14 @@ public: |
| 181 | 181 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 182 | 182 | |
| 183 | 183 | // First, add an atom using the Scheme shell |
| 184 | int rc = system("echo '(Concept \"mcp-test-concept\")' | nc -q 1 localhost 17334"); | |
| 184 | int rc = system("printf '(Concept \"mcp-test-concept\")\\n' | nc -q 1 localhost 17334"); | |
| 185 | 185 | TS_ASSERT_EQUALS(rc, 0); |
| 186 | 186 | usleep(50000); |
| 187 | 187 | |
| 188 | 188 | // Now use MCP shell to query for the atom |
| 189 | 189 | // -q3 because the guix test environment is slow as molasses. |
| 190 | 190 | std::string result = mcp_cmd_exec( |
| 191 | "echo 'mcp\\n{\"jsonrpc\": \"2.0\", \"method\": \"tools/call\", " | |
| 191 | "printf 'mcp\\n{\"jsonrpc\": \"2.0\", \"method\": \"tools/call\", " | |
| 192 | 192 | "\"params\": {\"name\": \"getAtoms\", \"arguments\": {\"type\": \"ConceptNode\"}}, " |
| 193 | 193 | "\"id\": 1}\\n' | nc -q 3 localhost 17334"); |
| 194 | 194 |
| … | … | @@ -53,7 +53,7 @@ void gargleblast(int tid, int reps) |
| 53 | 53 | { |
| 54 | 54 | int j = i + 10 + (tid+10)*1000; |
| 55 | 55 | char buf[1000]; |
| 56 | sprintf(buf, "echo '(Evaluation (Predicate \"visible face\") (List (Number %d)))\n' | nc -q 1 localhost 17333", j); | |
| 56 | sprintf(buf, "printf '(Evaluation (Predicate \"visible face\") (List (Number %d)))\\n' | nc -q 1 localhost 17333", j); | |
| 57 | 57 | |
| 58 | 58 | std::string reso = cmd_exec(buf); |
| 59 | 59 | |
| … | … | @@ -94,7 +94,7 @@ void gargleblast(int tid, int reps) |
| 94 | 94 | |
| 95 | 95 | if (20 <= i) |
| 96 | 96 | { |
| 97 | sprintf(buf, "echo '(cog-extract! (Evaluation (Predicate \"visible face\") (List (Number %d))))\n' | nc -q 1 localhost 17333", j-20); | |
| 97 | sprintf(buf, "printf '(cog-extract! (Evaluation (Predicate \"visible face\") (List (Number %d))))\\n' | nc -q 1 localhost 17333", j-20); | |
| 98 | 98 | std::string delo = cmd_exec(buf); |
| 99 | 99 | |
| 100 | 100 | // The new half-open detection code sends blanks. |
| … | … | @@ -256,23 +256,23 @@ public: |
| 256 | 256 | { |
| 257 | 257 | time_t t0 = time(0); |
| 258 | 258 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 259 | int rc = system("echo '(Concept \"42\")\n' | nc -q 0 localhost 17333"); | |
| 259 | int rc = system("printf '(Concept \"42\")\\n' | nc -q 0 localhost 17333"); | |
| 260 | 260 | if (rc != 0) printf("Error: first call failed\n"); |
| 261 | 261 | TS_ASSERT_EQUALS(rc, 0); |
| 262 | 262 | usleep(50000); |
| 263 | 263 | |
| 264 | 264 | // The hexadecimal \x4 is ctrl-D. |
| 265 | rc = system("echo 'scm\n(+ 2 2)\n\x4\n' | nc -q 0 localhost 17333"); | |
| 265 | rc = system("printf 'scm\\n(+ 2 2)\\n\x4\\n' | nc -q 0 localhost 17333"); | |
| 266 | 266 | if (rc != 0) printf("Error: second call failed\n"); |
| 267 | 267 | TS_ASSERT_EQUALS(rc, 0); |
| 268 | 268 | usleep(50000); |
| 269 | 269 | |
| 270 | rc = system("echo 'scm\n(Concept \"42\")\n' | nc -q 0 localhost 17333"); | |
| 270 | rc = system("printf 'scm\\n(Concept \"42\")\\n' | nc -q 0 localhost 17333"); | |
| 271 | 271 | if (rc != 0) printf("Error: third call failed\n"); |
| 272 | 272 | TS_ASSERT_EQUALS(rc, 0); |
| 273 | 273 | usleep(50000); |
| 274 | 274 | |
| 275 | rc = system("echo '(+ 2 2)\n.\n' | nc -q 0 localhost 17333"); | |
| 275 | rc = system("printf '(+ 2 2)\\n.\\n' | nc -q 0 localhost 17333"); | |
| 276 | 276 | if (rc != 0) printf("Error: fourth call failed\n"); |
| 277 | 277 | TS_ASSERT_EQUALS(rc, 0); |
| 278 | 278 | usleep(50000); |
| … | … | @@ -290,7 +290,7 @@ public: |
| 290 | 290 | // The hexadecimal \x16 is ctrl-C. |
| 291 | 291 | // The interrupt should kill the sleep immediately. |
| 292 | 292 | // Elapsed time should be well under a second. |
| 293 | int rc = system("echo '(sleep 42)\n\x16' | nc -q 0 localhost 17333"); | |
| 293 | int rc = system("printf '(sleep 42)\\n\x16' | nc -q 0 localhost 17333"); | |
| 294 | 294 | if (rc != 0) logger().warn("Error: first call failed"); |
| 295 | 295 | TS_ASSERT_EQUALS(rc, 0); |
| 296 | 296 | |
| … | … | @@ -300,7 +300,7 @@ public: |
| 300 | 300 | |
| 301 | 301 | start = time(0); |
| 302 | 302 | // The hexadecimal \x18 is ctrl-X aka "cancel" |
| 303 | rc = system("echo '(sleep 43)\n\x18' | nc -q 0 localhost 17333"); | |
| 303 | rc = system("printf '(sleep 43)\\n\x18' | nc -q 0 localhost 17333"); | |
| 304 | 304 | if (rc != 0) logger().warn("Error: first call failed"); |
| 305 | 305 | TS_ASSERT_EQUALS(rc, 0); |
| 306 | 306 | |
| … | … | @@ -310,7 +310,7 @@ public: |
| 310 | 310 | |
| 311 | 311 | start = time(0); |
| 312 | 312 | // The hexadecimal \x1b is ctrl-[ aka "escape" |
| 313 | rc = system("echo '(sleep 44)\n\x1b' | nc -q 0 localhost 17333"); | |
| 313 | rc = system("printf '(sleep 44)\\n\x1b' | nc -q 0 localhost 17333"); | |
| 314 | 314 | if (rc != 0) logger().warn("Error: second call failed"); |
| 315 | 315 | TS_ASSERT_EQUALS(rc, 0); |
| 316 | 316 | |
| … | … | @@ -332,16 +332,16 @@ public: |
| 332 | 332 | time_t t0 = time(0); |
| 333 | 333 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 334 | 334 | cmd_exec( |
| 335 | "echo 'scm\n (sleep 3) (Concept \"A\")\n" | |
| 336 | "(sleep 3)\n (Concept \"B\")\n" | |
| 337 | "(sleep 3)\n (Concept \"C\")\n' | nc -q 0 localhost 17333"); | |
| 335 | "printf 'scm\\n (sleep 3) (Concept \"A\")\\n" | |
| 336 | "(sleep 3)\\n (Concept \"B\")\\n" | |
| 337 | "(sleep 3)\\n (Concept \"C\")\\n' | nc -q 0 localhost 17333"); | |
| 338 | 338 | |
| 339 | 339 | // The barrier call here will force above to finish before the |
| 340 | 340 | // atomspace print below. We sleep one second, to make sure the |
| 341 | 341 | // above got started; we don't want the barrier to finish before |
| 342 | 342 | // the above starts. |
| 343 | 343 | sleep(1); |
| 344 | cmd_exec("echo 'scm\n (cog-global-barrier)' | nc -q 0 localhost 17333"); | |
| 344 | cmd_exec("printf 'scm\\n (cog-global-barrier)' | nc -q 0 localhost 17333"); | |
| 345 | 345 | |
| 346 | 346 | // Sleep one second, so as to let the barrier at least get started, |
| 347 | 347 | // before we ask to print the AtomSpace. The barrier should block |
| … | … | @@ -350,7 +350,7 @@ public: |
| 350 | 350 | // Use `nc -q 15` because it will take a while to respond. |
| 351 | 351 | sleep(1); |
| 352 | 352 | std::string ply = cmd_exec( |
| 353 | "echo 'scm\n (cog-prt-atomspace)' | nc -q 15 localhost 17333"); | |
| 353 | "printf 'scm\\n (cog-prt-atomspace)' | nc -q 15 localhost 17333"); | |
| 354 | 354 | |
| 355 | 355 | // Expect between 189 and 205 bytes; it seems a trailing |
| 356 | 356 | // prompt string is sometimes not received. I don't know |
| … | … | @@ -395,17 +395,17 @@ public: |
| 395 | 395 | { |
| 396 | 396 | time_t t0 = time(0); |
| 397 | 397 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 398 | std::string ply = cmd_exec("echo 'scm\n" | |
| 399 | // "(add-to-load-path \"/usr/local/share/opencog/scm\")\n" | |
| 398 | std::string ply = cmd_exec("printf 'scm\\n" | |
| 399 | // "(add-to-load-path \"/usr/local/share/opencog/scm\")\\n" | |
| 400 | 400 | // "(use-modules (opencog) (opencog logger))" |
| 401 | 401 | "(define (function-1 ticket) " |
| 402 | 402 | // " (cog-logger-info \"CALLED function-1 ~s\" ticket)" |
| 403 | " (string-append \"return-1-\" ticket \"-finished\"))\n" | |
| 403 | " (string-append \"return-1-\" ticket \"-finished\"))\\n" | |
| 404 | 404 | "(define (function-2 ticket) " |
| 405 | 405 | // " (cog-logger-info \"CALLED function-2 ~s\" ticket)" |
| 406 | " (string-append \"return-2-\" ticket \"-finished\"))\n" | |
| 407 | "(display \"Finished creating definitions\n\")" | |
| 408 | "\n.\n' | nc -q 2 localhost 17333"); | |
| 406 | " (string-append \"return-2-\" ticket \"-finished\"))\\n" | |
| 407 | "(display \"Finished creating definitions\\n\")" | |
| 408 | "\\n.\\n' | nc -q 2 localhost 17333"); | |
| 409 | 409 | |
| 410 | 410 | // The -q2 on `nc` should be enough for the above to finish up. |
| 411 | 411 | TS_ASSERT (0 < ply.size()); |