/* * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
privatelong input; private Unit inputUnit; privatelong result; private Unit resultUnit;
privatelong getValueAsUnit(long value, Unit unit) { switch (unit) { case b: return value; case k: return value / 1024; case m: return value / (1024 * 1024); case g: return value / (1024 * 1024 * 1024);
} return value;
}
privatelong getRawValue(long value, Unit unit) { switch (unit) { case b: return value; case k: return value * 1024; case m: return value * (1024 * 1024); case g: return value * (1024 * 1024 * 1024);
} return value;
}
privatelong parseValue(String valueString, char unit) { if (Character.isLetter(unit)) {
unit = Character.toLowerCase(unit); return getRawValue(Long.parseLong(valueString.substring(0, valueString.length() - 1), 10),
Unit.valueOf(String.valueOf(unit)));
} // does not have a unit, default is bytes returnLong.parseLong(valueString.substring(0, valueString.length()), 10);
}
publicboolean validate() throws IllegalArgumentException { // a result memory options should be page aligned if (getResult() > PAGE_SIZE) { if (getResult() % PAGE_SIZE != 0) { thrownew IllegalArgumentException("Result value: "
+ getResult() + " for option " + getOptionParamName() + " is not aligned to page size "+ PAGE_SIZE);
}
} // if min is defined, the result value should be gteq if (min != UNDEFINED) { if (getResult() < min) { thrownew IllegalArgumentException("Result value: "
+ getResult() + " for option " + getOptionParamName() + " is less than min: " + min);
}
} // if max is defined, the result values should be lteq if (max != UNDEFINED) { if (getResult() > max) { thrownew IllegalArgumentException("Result value: "
+ getResult() + " for option " + getOptionParamName() + " is greater than max: " + max);
}
} returntrue;
}
staticprivate List<TestCase> testCases = new ArrayList<TestCase>();
static { // positive example-based tests
TestCase tc = new TestCase("DefaultOptionsPositive", false); // defaults, no options explicitly set
testCases.add(tc);
// explicit defaults passed as parameters
tc = new TestCase("MemorySizePositive", false);
tc.setMemorySizeTestParam(10, 'm');
testCases.add(tc);
tc = new TestCase("GlobalBufferSizePositive", false);
tc.setGlobalBufferSizeTestParam(512, 'k');
testCases.add(tc);
tc = new TestCase("BufferCountPositive", false);
tc.setGlobalBufferCountTestParam(20, 'b');
testCases.add(tc);
tc = new TestCase("ThreadBufferSizePositive", false);
tc.setThreadBufferSizeTestParam(Option.DEFAULT_THREAD_BUFFER_SIZE, 'b');
testCases.add(tc);
// negative example-based tests, each individual option below minimum size
tc = new TestCase("MemorySizeBelowMinNegative", false);
tc.setMemorySizeTestParam(Option.MIN_MEMORY_SIZE - 1, 'b');
testCases.add(tc);
tc = new TestCase("GlobalBufferSizeBelowMinNegative", false);
tc.setGlobalBufferSizeTestParam(Option.MIN_GLOBAL_BUFFER_SIZE - 1, 'b');
testCases.add(tc);
tc = new TestCase("BufferCountBelowMinNegative", false);
tc.setGlobalBufferCountTestParam(Option.MIN_GLOBAL_BUFFER_COUNT - 1, 'b');
testCases.add(tc);
tc = new TestCase("ThreadBufferSizeBelowMinNegative", false);
tc.setThreadBufferSizeTestParam(Option.MIN_THREAD_BUFFER_SIZE - 1, 'b');
testCases.add(tc);
// Memory size permutations // a few single memorysize option for deduction
tc = new TestCase("MemorySizeValue1Positive", false);
tc.setMemorySizeTestParam(48128, 'k'); // 47mb
testCases.add(tc);
tc = new TestCase("MemorySizeGlobalBufferSizeBufferCountPositive", false);
tc.setMemorySizeTestParam(12240, 'k');
tc.setGlobalBufferSizeTestParam(720, 'k'); // 720 k * 17 == 12240 k
tc.setGlobalBufferCountTestParam(17, 'b');
testCases.add(tc);
tc = new TestCase("MemorySizeGlobalBufferSizeBufferCountThreadBufferSizePositive", false);
tc.setMemorySizeTestParam(12240, 'k');
tc.setGlobalBufferSizeTestParam(720, 'k'); // 720 k * 17 == 12240 k
tc.setGlobalBufferCountTestParam(17, 'b');
tc.setThreadBufferSizeTestParam(600, 'k');
testCases.add(tc);
// negative example-based test, create an ambiguous situtation
tc = new TestCase("MemorySizeGlobalBufferSizeBufferCountAmbiguousNegative", false);
tc.setMemorySizeTestParam(12240, 'k');
tc.setGlobalBufferSizeTestParam(720, 'k'); // 720 k * 19 != 12240 k
tc.setGlobalBufferCountTestParam(19, 'b');
testCases.add(tc);
// Global buffer size permutations
tc = new TestCase("GlobalBufferSizeBufferCountPositive", false);
tc.setGlobalBufferSizeTestParam(917, 'k');
tc.setGlobalBufferCountTestParam(31, 'b');
testCases.add(tc);
tc = new TestCase("GlobalBufferSizeBufferCountThreadBufferSizePositive", false);
tc.setGlobalBufferSizeTestParam(917, 'k');
tc.setGlobalBufferCountTestParam(31, 'b');
tc.setThreadBufferSizeTestParam(760832, 'b'); // 743 k
testCases.add(tc);
// negative example-based test, let thread buffer size > global buffer size
tc = new TestCase("GlobalBufferSizeLessThanThreadBufferSizeNegative", false);
tc.setGlobalBufferSizeTestParam(917, 'k');
tc.setThreadBufferSizeTestParam(1317, 'k');
testCases.add(tc);
// explicitly specifying global buffer size and global buffer count must be gteq min memorysize
tc = new TestCase("GlobalBufferSizeTimesGlobalBufferCountLessThanMinMemorySizeNegative", false);
tc.setGlobalBufferSizeTestParam(67857, 'b');
tc.setGlobalBufferCountTestParam(3, 'b');
testCases.add(tc);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.