From ca78df24bafb088d340f7edb02ff664e5cad541a Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 11 Jan 2018 14:55:22 +0000 Subject: [PATCH 1/8] PHPC-1081: Make driver compile on 32-bit platforms without warning --- php_phongo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php_phongo.c b/php_phongo.c index 7c89f8ae3..b959504e4 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -230,7 +230,7 @@ static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain, dt = php_format_date((char *) ZEND_STRL("Y-m-d\\TH:i:s"), t, 0 TSRMLS_CC); - fprintf(MONGODB_G(debug_fd), "[%s.%06lu+00:00] %10s: %-8s> %s\n", ZSTR_VAL(dt), tu, log_domain, mongoc_log_level_str(log_level), message); + fprintf(MONGODB_G(debug_fd), "[%s.%06" PHONGO_LONG_FORMAT "+00:00] %10s: %-8s> %s\n", ZSTR_VAL(dt), tu, log_domain, mongoc_log_level_str(log_level), message); fflush(MONGODB_G(debug_fd)); efree(dt); } From d1563898e6df2e5451d33d1a54b8d80b0b1797ab Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 11 Jan 2018 14:57:02 +0000 Subject: [PATCH 2/8] Disable tests for Int64 type that can not work on a 32-bit platform --- scripts/convert-bson-corpus-tests.php | 18 +++++++++++++----- tests/bson-corpus/int64-valid-001.phpt | 2 ++ tests/bson-corpus/int64-valid-002.phpt | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/convert-bson-corpus-tests.php b/scripts/convert-bson-corpus-tests.php index 67b773611..d33b98433 100644 --- a/scripts/convert-bson-corpus-tests.php +++ b/scripts/convert-bson-corpus-tests.php @@ -14,6 +14,11 @@ 'Top-level document validity: Bad $date (number, not string or hash)' => 'Legacy extended JSON $date syntax uses numbers (CDRIVER-2223)', ]; +$for64bitOnly = [ + 'Int64 type: MinValue' => "Can't represent 64-bit ints on a 32-bit platform", + 'Int64 type: MaxValue' => "Can't represent 64-bit ints on a 32-bit platform", +]; + $outputPath = realpath(__DIR__ . '/../tests') . '/bson-corpus/'; if ( ! is_dir($outputPath) && ! mkdir($outputPath, 0755, true)) { @@ -42,7 +47,7 @@ foreach ($test['valid'] as $i => $case) { $outputFile = sprintf('%s-valid-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1); try { - $output = renderPhpt(getParamsForValid($test, $case), $expectedFailures); + $output = renderPhpt(getParamsForValid($test, $case), $expectedFailures, $for64bitOnly); } catch (Exception $e) { printf("Error processing valid[%d] in %s: %s\n", $i, $inputFile, $e->getMessage()); continue; @@ -59,7 +64,7 @@ foreach ($test['decodeErrors'] as $i => $case) { $outputFile = sprintf('%s-decodeError-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1); try { - $output = renderPhpt(getParamsForDecodeError($test, $case), $expectedFailures); + $output = renderPhpt(getParamsForDecodeError($test, $case), $expectedFailures, $for64bitOnly); } catch (Exception $e) { printf("Error processing decodeErrors[%d] in %s: %s\n", $i, $inputFile, $e->getMessage()); continue; @@ -76,7 +81,7 @@ foreach ($test['parseErrors'] as $i => $case) { $outputFile = sprintf('%s-parseError-%03d.phpt', pathinfo($inputFile, PATHINFO_FILENAME), $i + 1); try { - $output = renderPhpt(getParamsForParseError($test, $case), $expectedFailures); + $output = renderPhpt(getParamsForParseError($test, $case), $expectedFailures, $for64bitOnly); } catch (Exception $e) { printf("Error processing parseErrors[%d] in %s: %s\n", $i, $inputFile, $e->getMessage()); continue; @@ -263,16 +268,19 @@ function getParamsForParseError(array $test, array $case) ]; } -function renderPhpt(array $params, array $expectedFailures) +function renderPhpt(array $params, array $expectedFailures, array $for64bitOnly) { $params['%XFAIL%'] = isset($expectedFailures[$params['%NAME%']]) ? "--XFAIL--\n" . $expectedFailures[$params['%NAME%']] . "\n" : ''; + $params['%SKIPIF%'] = isset($for64bitOnly[$params['%NAME%']]) + ? "--SKIPIF--\n" . "" . "\n" + : ''; $template = <<< 'TEMPLATE' --TEST-- %NAME% -%XFAIL%--DESCRIPTION-- +%XFAIL%%SKIPIF%--DESCRIPTION-- Generated by scripts/convert-bson-corpus-tests.php DO NOT EDIT THIS FILE diff --git a/tests/bson-corpus/int64-valid-001.phpt b/tests/bson-corpus/int64-valid-001.phpt index cae95fa9a..4f63a6d7a 100644 --- a/tests/bson-corpus/int64-valid-001.phpt +++ b/tests/bson-corpus/int64-valid-001.phpt @@ -1,5 +1,7 @@ --TEST-- Int64 type: MinValue +--SKIPIF-- + --DESCRIPTION-- Generated by scripts/convert-bson-corpus-tests.php diff --git a/tests/bson-corpus/int64-valid-002.phpt b/tests/bson-corpus/int64-valid-002.phpt index 7d4468a36..394af40b0 100644 --- a/tests/bson-corpus/int64-valid-002.phpt +++ b/tests/bson-corpus/int64-valid-002.phpt @@ -1,5 +1,7 @@ --TEST-- Int64 type: MaxValue +--SKIPIF-- + --DESCRIPTION-- Generated by scripts/convert-bson-corpus-tests.php From 4a178a3b7957000ef2395d7624713dc6169e8264 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 11 Jan 2018 14:57:37 +0000 Subject: [PATCH 3/8] Disable test that fails on 32-bit platforms because the cursor ID can not be represented --- tests/cursor/cursor-destruct-001.phpt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cursor/cursor-destruct-001.phpt b/tests/cursor/cursor-destruct-001.phpt index f91eba6a7..63135bb94 100644 --- a/tests/cursor/cursor-destruct-001.phpt +++ b/tests/cursor/cursor-destruct-001.phpt @@ -1,6 +1,7 @@ --TEST-- MongoDB\Driver\Cursor destruct should kill a live cursor --SKIPIF-- + --FILE-- From a0c1b539fd76ed90956ada2e735b11f1830e8a87 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 11 Jan 2018 14:57:52 +0000 Subject: [PATCH 4/8] Fix test due to quirck in PHP parser --- tests/bson/bson-timestamp_error-003.phpt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/bson/bson-timestamp_error-003.phpt b/tests/bson/bson-timestamp_error-003.phpt index 459ad0977..3e91b5f2b 100644 --- a/tests/bson/bson-timestamp_error-003.phpt +++ b/tests/bson/bson-timestamp_error-003.phpt @@ -10,7 +10,10 @@ echo throws(function() { }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; echo throws(function() { - new MongoDB\BSON\Timestamp(-2147483648, 0); + /* I realise that "-2147483647 - 1" could be written as "-2147483648", *however*, PHP considers + * the latter a floating point number, as it parses "-" and "2147483648" separately, and + * "2147483648" doesn't fit in the 32-bit signed range. */ + new MongoDB\BSON\Timestamp(-2147483647 - 1, 0); }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; echo throws(function() { @@ -18,7 +21,7 @@ echo throws(function() { }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; echo throws(function() { - new MongoDB\BSON\Timestamp(0, -2147483648); + new MongoDB\BSON\Timestamp(0, -2147483647 - 1); }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; ?> From 1e06f3428f01e4bef4b844226f60e1fa78ef6961 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 11 Jan 2018 15:49:27 +0000 Subject: [PATCH 5/8] Replace check for 'TRAVIS' with MongoDB server version check --- .../causal-consistency-011.phpt | 3 +-- tests/manager/manager-executeCommand-004.phpt | 3 +-- .../manager-executeReadCommand-001.phpt | 3 +-- .../manager-executeWriteCommand-001.phpt | 3 +-- tests/server/server-executeCommand-006.phpt | 3 +-- .../server/server-executeReadCommand-001.phpt | 3 +-- .../server-executeWriteCommand-001.phpt | 3 +-- tests/session/session-001.phpt | 3 +-- tests/session/session-003.phpt | 3 +-- tests/session/session-debug-001.phpt | 3 +-- tests/session/session-debug-003.phpt | 3 +-- .../session-getLogicalSessionId-001.phpt | 3 +-- tests/utils/tools.php | 25 ++++++++++++++++--- 13 files changed, 34 insertions(+), 27 deletions(-) diff --git a/tests/causal-consistency/causal-consistency-011.phpt b/tests/causal-consistency/causal-consistency-011.phpt index 568e686a7..ef4b79231 100644 --- a/tests/causal-consistency/causal-consistency-011.phpt +++ b/tests/causal-consistency/causal-consistency-011.phpt @@ -1,9 +1,8 @@ --TEST-- Causal consistency: $clusterTime is not sent in commands to unsupported deployments --SKIPIF-- - - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- - + --FILE-- 1]); + $rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY); + + try { + $cursor = $manager->executeCommand("admin", $cmd, $rp); + $cursor->setTypeMap(['root' => 'array', 'document' => 'array']); + $document = current($cursor->toArray()); + + if (version_compare($document['version'], $version, '<')) { + echo "skip Needs version >= $version, but is {$document['version']}"; + } + } catch(Exception $e) { + echo "skip (needs version); $uri ($version): " . $e->getCode(), ": ", $e->getMessage(); + exit(1); + } +} + function CLEANUP($uri, $dbname = DATABASE_NAME, $collname = COLLECTION_NAME) { try { $manager = new MongoDB\Driver\Manager($uri); From 86ac6ec4ffdd0ae02095606f7e3691fdecaf02fb Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 11 Jan 2018 15:54:00 +0000 Subject: [PATCH 6/8] Re-enable test that was disabled for ages as it works fine on Travis now. --- tests/manager/manager-executeBulkWrite-008.phpt | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/manager/manager-executeBulkWrite-008.phpt b/tests/manager/manager-executeBulkWrite-008.phpt index d4aed4d05..f7e6c1b99 100644 --- a/tests/manager/manager-executeBulkWrite-008.phpt +++ b/tests/manager/manager-executeBulkWrite-008.phpt @@ -1,7 +1,6 @@ --TEST-- MongoDB\Driver\Manager::executeBulkWrite() update multiple documents with no upsert --SKIPIF-- - --FILE-- From 0465d4f2e7243a5e9d87c9314a479c3636f50cc3 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 11 Jan 2018 17:43:29 +0000 Subject: [PATCH 7/8] PHPC-1093: Bound checking on 32-bit platforms for APM's duration_micros --- phongo_compat.h | 18 +++++++++--------- src/MongoDB/Monitoring/CommandFailedEvent.c | 2 +- src/MongoDB/Monitoring/CommandSucceededEvent.c | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/phongo_compat.h b/phongo_compat.h index edd7bf234..af175a4b3 100644 --- a/phongo_compat.h +++ b/phongo_compat.h @@ -143,22 +143,22 @@ # define ADD_ASSOC_INT64(zval, key, value) add_assoc_long(zval, key, value) #elif SIZEOF_PHONGO_LONG == 4 # define ADD_INDEX_INT64(zval, index, value) \ - if (value > INT32_MAX || value < INT32_MIN) { \ - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \ + if ((value) > INT32_MAX || (value) < INT32_MIN) { \ + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \ } else { \ - add_index_long(zval, index, value); \ + add_index_long(zval, index, (value)); \ } # define ADD_NEXT_INDEX_INT64(zval, value) \ - if (value > INT32_MAX || value < INT32_MIN) { \ - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \ + if ((value) > INT32_MAX || (value) < INT32_MIN) { \ + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \ } else { \ - add_next_index_long(zval, value); \ + add_next_index_long(zval, (value)); \ } # define ADD_ASSOC_INT64(zval, key, value) \ - if (value > INT32_MAX || value < INT32_MIN) { \ - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \ + if ((value) > INT32_MAX || (value) < INT32_MIN) { \ + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \ } else { \ - add_assoc_long(zval, key, value); \ + add_assoc_long(zval, key, (value)); \ } #else # error Unsupported architecture (integers are neither 32-bit nor 64-bit) diff --git a/src/MongoDB/Monitoring/CommandFailedEvent.c b/src/MongoDB/Monitoring/CommandFailedEvent.c index a336d49f5..c79abd6a8 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent.c +++ b/src/MongoDB/Monitoring/CommandFailedEvent.c @@ -214,7 +214,7 @@ static HashTable *php_phongo_commandfailedevent_get_debug_info(zval *object, int array_init_size(&retval, 6); ADD_ASSOC_STRING(&retval, "commandName", intern->command_name); - ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros); + ADD_ASSOC_INT64(&retval, "durationMicros", (int64_t) intern->duration_micros); #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL_EX(&retval, "error", &intern->z_error); diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent.c b/src/MongoDB/Monitoring/CommandSucceededEvent.c index b1a4c5fdf..fe6d0d4d0 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent.c +++ b/src/MongoDB/Monitoring/CommandSucceededEvent.c @@ -216,7 +216,7 @@ static HashTable *php_phongo_commandsucceededevent_get_debug_info(zval *object, array_init_size(&retval, 6); ADD_ASSOC_STRING(&retval, "commandName", intern->command_name); - ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros); + ADD_ASSOC_INT64(&retval, "durationMicros", (int64_t) intern->duration_micros); sprintf(operation_id, "%" PHONGO_LONG_FORMAT, intern->operation_id); ADD_ASSOC_STRING(&retval, "operationId", operation_id); From d0d3cc7f9616b598cb82c60770c6c51b3271842e Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Fri, 12 Jan 2018 11:54:58 +0000 Subject: [PATCH 8/8] Ensure these tests only run with wiredTiger engine --- .../manager-executeReadCommand-001.phpt | 2 +- .../server/server-executeReadCommand-001.phpt | 2 +- tests/utils/tools.php | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/manager/manager-executeReadCommand-001.phpt b/tests/manager/manager-executeReadCommand-001.phpt index 085d48fd6..dbc99213c 100644 --- a/tests/manager/manager-executeReadCommand-001.phpt +++ b/tests/manager/manager-executeReadCommand-001.phpt @@ -2,7 +2,7 @@ MongoDB\Driver\Manager::executeReadCommand() --SKIPIF-- - + --FILE-- - + --FILE-- 1]); + $rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::RP_PRIMARY); + + try { + $cursor = $manager->executeCommand("admin", $cmd, $rp); + $cursor->setTypeMap(['root' => 'array', 'document' => 'array']); + $document = current($cursor->toArray()); + + if ($document['storageEngine']['name'] != $engine) { + echo "skip Needs storage engine '$engine', but is '{$document['storageEngine']['name']}'"; + } + } catch(Exception $e) { + echo "skip (needs version); $uri ($version): " . $e->getCode(), ": ", $e->getMessage(); + exit(1); + } +} + function CLEANUP($uri, $dbname = DATABASE_NAME, $collname = COLLECTION_NAME) { try { $manager = new MongoDB\Driver\Manager($uri);