Lines Matching refs:file

5  * you may not use this file except in compliance with the License.
18 * For each spec file provided on the command line, it generates a corresponding
23 * - a Renderscript file named Test{Function}.rs,
24 * - a Junit file named Test{function}.java, which calls the above RS file.
27 * test files for. The header file will always contain all the functions.
30 * - SpecFile: Represents on spec file.
32 * spec file contains many entries for clamp, we'll only have one clamp instance.
35 * spec file. Strings that are parts of a Specification can include placeholders,
62 "// Don't edit this file! It is auto-generated by "
69 " * you may not use this file except in compliance with the License.\n"
105 string specName; // e.g. x, as found in the spec file
125 /* Parse the parameter definition found in the spec file. It will generate a name if none
126 * are present in the file. One of the two counts will be incremented, and potentially
133 // An entire spec file and the methods to process it.
153 /* Represents a function, like "clamp". Even though the spec file contains many entries for clamp,
166 /* We keep track of the allocations generated in the .rs file and the argument classes defined
167 * in the Java file, as we share these between the functions created for each specification.
174 ofstream mRsFile; // The Renderscript test file we're generating.
175 ofstream mJavaFile; // The Jave test file we're generating.
178 bool writeRelaxedRsFile(); // Write the entire relaxed rs test file (an include essentially)
180 void finishJavaFile(); // Write the test method and closes the file.
186 * to test. Also writes the section of the header file.
193 // Add a call to mJavaCallAllCheckMethods to be used at the end of the file generation.
198 * Specification objects and entries in the spec file. Some of the strings that are parts of a
316 void writeHeaderSection(ofstream& file) const;
320 void writeJavaSection(ofstream& file) const;
321 void writeJavaArgumentClass(ofstream& file, bool scalar) const;
322 void writeJavaCheckMethod(ofstream& file, bool generateCallToVerifier) const;
323 void writeJavaVerifyScalarMethod(ofstream& file, bool verifierValidates) const;
324 void writeJavaVerifyVectorMethod(ofstream& file) const;
325 void writeJavaVerifyFunctionHeader(ofstream& file) const;
326 void writeJavaInputAllocationDefinition(ofstream& file, const string& indent,
328 void writeJavaOutputAllocationDefinition(ofstream& file, const string& indent,
331 void writeJavaRandomCompatibleFloatAllocation(ofstream& file, const string& dataType,
335 void writeJavaRandomCompatibleIntegerAllocation(ofstream& file, const string& dataType,
339 void writeJavaCallToRs(ofstream& file, bool relaxed, bool generateCallToVerifier) const;
341 void writeJavaTestAndSetValid(ofstream& file, int indent, const ParameterDefinition& p,
343 void writeJavaTestOneValue(ofstream& file, int indent, const ParameterDefinition& p,
345 void writeJavaAppendOutputToMessage(ofstream& file, int indent, const ParameterDefinition& p,
348 void writeJavaAppendInputToMessage(ofstream& file, int indent, const ParameterDefinition& p,
350 void writeJavaAppendNewLineToMessage(ofstream& file, int indent) const;
351 void writeJavaAppendVariableToMessage(ofstream& file, int indent, const ParameterDefinition& p,
353 void writeJavaAppendFloatVariableToMessage(ofstream& file, int indent, const string& value,
355 void writeJavaVectorComparison(ofstream& file, int indent, const ParameterDefinition& p) const;
356 void writeJavaAppendVectorInputToMessage(ofstream& file, int indent,
358 void writeJavaAppendVectorOutputToMessage(ofstream& file, int indent,
375 const char* specType; // Name found in the .spec file
377 string cType; // Type in a C file
378 const char* javaType; // Type in a Java file
499 // Return the next line from the input file.
511 void writeIfdef(ofstream& file, string filename, bool isStart) {
523 file << "#ifndef " << t << "\n";
524 file << "#define " << t << "\n";
526 file << "#endif // " << t << "\n";
530 void writeJavaArrayInitialization(ofstream& file, const ParameterDefinition& p) {
531 file << tab(2) << p.javaBaseType << "[] " << p.javaArrayName << " = new " << p.javaBaseType
533 file << tab(2) << p.javaAllocName << ".copyTo(" << p.javaArrayName << ");\n";
562 printf("No spec file specified\n");
700 printf("Error opening input file: %s\n", mSpecFileName.c_str());
728 // The header file name should have the same base but with a ".rsh" extension.
739 // Write the start of the header file.
743 printf("Error opening output file: %s\n", headerFileName.c_str());
753 // Finish the header file.
799 // There's no work to wrap-up in the .rs file.
810 printf("Error opening file: %s\n", fileName.c_str());
820 // Write an allocation definition if not already emitted in the .rs file.
827 // Write the entire *Relaxed.rs test file, as it only depends on the name.
830 FILE* file = fopen(name.c_str(), "wt");
831 if (!file) {
832 printf("Error opening file: %s\n", name.c_str());
835 fputs(LEGAL_NOTICE, file);
840 fputs(s.c_str(), file);
841 fclose(file);
849 printf("Error opening file: %s\n", fileName.c_str());
1177 void Permutation::writeHeaderSection(ofstream& file) const {
1184 file << "#if (defined(RS_VERSION) && (RS_VERSION >= " << minVersion
1187 file << "#if (defined(RS_VERSION) && (RS_VERSION >= " << minVersion << "))\n";
1191 file << "/*\n";
1194 file << " * " << mComment[ct] << "\n";
1196 file << " *\n";
1199 file << " *\n";
1202 file << " * Suppored by API versions " << minVersion << " - " << maxVersion << "\n";
1204 file << " * Supported by API versions " << minVersion << " and newer.\n";
1207 file << " */\n";
1209 file << "static ";
1211 file << "extern ";
1214 file << mParams[mReturnIndex]->rsType;
1216 file << "void";
1218 file << " __attribute__((";
1220 file << "const, ";
1222 file << "overloadable))";
1223 file << mName;
1224 file << "(";
1230 file << ", ";
1232 file << p.rsType;
1234 file << "*";
1237 file << " " << p.specName;
1243 file << ") {\n";
1245 file << " " << mInline[ct].c_str() << "\n";
1247 file << "}\n";
1249 file << ");\n";
1252 file << "#endif\n";
1254 file << "\n";
1257 /* Write the section of the .rs file for this permutation.
1287 * meanings in a .rs file.
1388 void Permutation::writeJavaSection(ofstream& file) const {
1391 writeJavaArgumentClass(file, true);
1392 writeJavaCheckMethod(file, true);
1393 writeJavaVerifyScalarMethod(file, false);
1395 writeJavaArgumentClass(file, true);
1396 writeJavaCheckMethod(file, true);
1397 writeJavaVerifyScalarMethod(file, true);
1399 writeJavaArgumentClass(file, false);
1400 writeJavaCheckMethod(file, true);
1401 writeJavaVerifyVectorMethod(file);
1403 writeJavaCheckMethod(file, false);
1410 void Permutation::writeJavaArgumentClass(ofstream& file, bool scalar) const {
1437 void Permutation::writeJavaCheckMethod(ofstream& file, bool generateCallToVerifier) const {
1438 file << tab(1) << "private void " << mJavaCheckMethodName << "() {\n";
1443 writeJavaInputAllocationDefinition(file, tab(2), p);
1451 file << tab(2) << "enforceOrdering(" << smallerAlloc << ", " << p.javaAllocName
1455 writeJavaCallToRs(file, false, generateCallToVerifier);
1456 writeJavaCallToRs(file, true, generateCallToVerifier);
1457 file << tab(1) << "}\n\n";
1460 void Permutation::writeJavaInputAllocationDefinition(ofstream& file, const string& indent,
1467 file << indent << "Allocation " << param.javaAllocName << " = ";
1470 writeJavaRandomCompatibleFloatAllocation(file, dataType, seed, vectorSize,
1474 writeJavaRandomCompatibleIntegerAllocation(file, dataType, seed, vectorSize,
1482 file << "createRandomFloatAllocation(mRS, Element.DataType." << dataType << ", "
1487 file << "createRandomAllocation(mRS, Element.DataType." << dataType << ", " << vectorSize
1492 file << ";\n";
1495 void Permutation::writeJavaRandomCompatibleFloatAllocation(ofstream& file, const string& dataType,
1499 file << "createRandomFloatAllocation"
1523 file << scientific << std::setprecision(19);
1524 file << minValue << ", " << maxValue << ")";
1525 file.unsetf(ios_base::floatfield);
1528 void Permutation::writeJavaRandomCompatibleIntegerAllocation(ofstream& file, const string& dataType,
1532 file << "createRandomIntegerAllocation"
1538 file << (isSigned ? "true" : "false") << ", " << generatedType.significantBits;
1542 file << (isSigned ? "true" : "false") << ", "
1545 file << ")";
1548 void Permutation::writeJavaOutputAllocationDefinition(ofstream& file, const string& indent,
1553 file << indent << "Allocation " << param.javaAllocName << " = Allocation.createSized(mRS, "
1578 void Permutation::writeJavaVerifyScalarMethod(ofstream& file, bool verifierValidates) const {
1579 writeJavaVerifyFunctionHeader(file);
1583 writeJavaArrayInitialization(file, p);
1593 file << tab(2) << "for (int i = 0; i < INPUTSIZE; i++) {\n";
1594 file << tab(3) << "for (int j = 0; j < " << vectorSize << " ; j++) {\n";
1596 file << tab(4) << "// Extract the inputs.\n";
1597 file << tab(4) << mJavaArgumentsClassName << " args = new " << mJavaArgumentsClassName
1602 file << tab(4) << "args." << p.variableName << " = " << p.javaArrayName << "[i";
1604 file << " * " << p.vectorWidth << " + j";
1606 file << "];\n";
1611 file << tab(4) << "// Extract the outputs.\n";
1615 file << tab(4) << "args." << p.variableName << " = " << p.javaArrayName
1619 file << tab(4) << "// Ask the CoreMathVerifier to validate.\n";
1621 file << tab(4) << "Target target = new Target(relaxed);\n";
1623 file << tab(4) << "String errorMessage = CoreMathVerifier." << mJavaVerifierVerifyMethodName
1626 file << ", target";
1628 file << ");\n";
1629 file << tab(4) << "boolean valid = errorMessage == null;\n";
1631 file << tab(4) << "// Figure out what the outputs should have been.\n";
1633 file << tab(4) << "Target target = new Target(relaxed);\n";
1635 file << tab(4) << "CoreMathVerifier." << mJavaVerifierComputeMethodName << "(args";
1637 file << ", target";
1639 file << ");\n";
1640 file << tab(4) << "// Validate the outputs.\n";
1641 file << tab(4) << "boolean valid = true;\n";
1645 writeJavaTestAndSetValid(file, 4, p, "", "[i * " + p.vectorWidth + " + j]");
1650 file << tab(4) << "if (!valid) {\n";
1651 file << tab(5) << "StringBuilder message = new StringBuilder();\n";
1655 writeJavaAppendOutputToMessage(file, 5, p, "", "[i * " + p.vectorWidth + " + j]",
1658 writeJavaAppendInputToMessage(file, 5, p, "args." + p.variableName);
1662 file << tab(5) << "message.append(errorMessage);\n";
1665 file << tab(5) << "assertTrue(\"Incorrect output for " << mJavaCheckMethodName << "\" +\n";
1666 file << tab(7) << "(relaxed ? \"_relaxed\" : \"\") + \":\\n\" + message.toString(), valid);\n";
1667 file << tab(4) << "}\n";
1668 file << tab(3) << "}\n";
1669 file << tab(2) << "}\n";
1670 file << tab(1) << "}\n\n";
1673 void Permutation::writeJavaVerifyFunctionHeader(ofstream& file) const {
1674 file << tab(1) << "private void " << mJavaVerifyMethodName << "(";
1677 file << "Allocation " << p.javaAllocName << ", ";
1679 file << "boolean relaxed) {\n";
1682 void Permutation::writeJavaTestAndSetValid(ofstream& file, int indent, const ParameterDefinition& p,
1685 writeJavaTestOneValue(file, indent, p, argsIndex, actualIndex);
1686 file << tab(indent + 1) << "valid = false;\n";
1687 file << tab(indent) << "}\n";
1690 void Permutation::writeJavaTestOneValue(ofstream& file, int indent, const ParameterDefinition& p,
1692 file << tab(indent) << "if (";
1694 file << "!args." << p.variableName << argsIndex << ".couldBe(" << p.javaArrayName
1697 file << ", " << mPrecisionLimit;
1699 file << ")";
1701 file << "args." << p.variableName << argsIndex << " != " << p.javaArrayName << actualIndex;
1704 file << " && !args." << mParams[mReturnIndex]->variableName << argsIndex << ".isNaN()";
1706 file << ") {\n";
1709 void Permutation::writeJavaAppendOutputToMessage(ofstream& file, int indent,
1715 file << tab(indent) << "message.append(\"Output " + p.variableName + ": \");\n";
1717 writeJavaAppendFloatVariableToMessage(file, indent, actual, true);
1719 writeJavaAppendVariableToMessage(file, indent, p, actual);
1721 writeJavaAppendNewLineToMessage(file, indent);
1725 file << tab(indent) << "message.append(\"Expected output " + p.variableName + ": \");\n";
1727 writeJavaAppendFloatVariableToMessage(file, indent, expected, false);
1729 writeJavaAppendVariableToMessage(file, indent, p, expected);
1731 writeJavaAppendNewLineToMessage(file, indent);
1732 file << tab(indent) << "message.append(\"Actual output " + p.variableName + ": \");\n";
1733 writeJavaAppendVariableToMessage(file, indent, p, actual);
1735 writeJavaTestOneValue(file, indent, p, argsIndex, actualIndex);
1736 file << tab(indent + 1) << "message.append(\" FAIL\");\n";
1737 file << tab(indent) << "}\n";
1738 writeJavaAppendNewLineToMessage(file, indent);
1742 void Permutation::writeJavaAppendInputToMessage(ofstream& file, int indent,
1745 file << tab(indent) << "message.append(\"Input " + p.variableName + ": \");\n";
1746 writeJavaAppendVariableToMessage(file, indent, p, actual);
1747 writeJavaAppendNewLineToMessage(file, indent);
1750 void Permutation::writeJavaAppendNewLineToMessage(ofstream& file, int indent) const {
1751 file << tab(indent) << "message.append(\"\\n\");\n";
1754 void Permutation::writeJavaAppendVariableToMessage(ofstream& file, int indent,
1758 file << tab(indent) << "message.append(String.format(\"%14.8g {%8x} %15a\",\n";
1759 file << tab(indent + 2) << value << ", "
1762 file << tab(indent) << "message.append(String.format(\"%24.8g {%16x} %31a\",\n";
1763 file << tab(indent + 2) << value << ", "
1766 file << tab(indent) << "message.append(String.format(\"0x%x\", " << value << "));\n";
1768 file << tab(indent) << "message.append(String.format(\"%d\", " << value << "));\n";
1772 void Permutation::writeJavaAppendFloatVariableToMessage(ofstream& file, int indent,
1775 file << tab(indent) << "message.append(";
1777 file << "Float.toString(" << value << ")";
1779 file << value << ".toString()";
1781 file << ");\n";
1784 void Permutation::writeJavaVectorComparison(ofstream& file, int indent,
1787 writeJavaTestAndSetValid(file, indent, p, "", "[i]");
1790 file << tab(indent) << "for (int j = 0; j < " << p.mVectorSize << " ; j++) {\n";
1791 writeJavaTestAndSetValid(file, indent + 1, p, "[j]", "[i * " + p.vectorWidth + " + j]");
1792 file << tab(indent) << "}\n";
1796 void Permutation::writeJavaAppendVectorInputToMessage(ofstream& file, int indent,
1799 writeJavaAppendInputToMessage(file, indent, p, p.javaArrayName + "[i]");
1801 file << tab(indent) << "for (int j = 0; j < " << p.mVectorSize << " ; j++) {\n";
1802 writeJavaAppendInputToMessage(file, indent + 1, p,
1804 file << tab(indent) << "}\n";
1808 void Permutation::writeJavaAppendVectorOutputToMessage(ofstream& file, int indent,
1811 writeJavaAppendOutputToMessage(file, indent, p, "", "[i]", false);
1814 file << tab(indent) << "for (int j = 0; j < " << p.mVectorSize << " ; j++) {\n";
1815 writeJavaAppendOutputToMessage(file, indent + 1, p, "[j]",
1817 file << tab(indent) << "}\n";
1821 void Permutation::writeJavaVerifyVectorMethod(ofstream& file) const {
1822 writeJavaVerifyFunctionHeader(file);
1825 writeJavaArrayInitialization(file, p);
1827 file << tab(2) + "for (int i = 0; i < INPUTSIZE; i++) {\n";
1828 file << tab(3) << mJavaArgumentsNClassName << " args = new " << mJavaArgumentsNClassName
1831 file << tab(3) << "// Create the appropriate sized arrays in args\n";
1839 file << tab(3) << "args." << p.variableName << " = new " << type << "[" << p.mVectorSize
1844 file << tab(3) << "// Fill args with the input values\n";
1849 file << tab(3) << "args." << p.variableName << " = " << p.javaArrayName + "[i]"
1852 file << tab(3) << "for (int j = 0; j < " << p.mVectorSize << " ; j++) {\n";
1853 file << tab(4) << "args." << p.variableName + "[j] = "
1856 file << tab(3) << "}\n";
1860 file << tab(3) << "Target target = new Target(relaxed);\n";
1861 file << tab(3) << "CoreMathVerifier." << mJavaVerifierComputeMethodName
1864 file << tab(3) << "// Compare the expected outputs to the actual values returned by RS.\n";
1865 file << tab(3) << "boolean valid = true;\n";
1869 writeJavaVectorComparison(file, 3, p);
1873 file << tab(3) << "if (!valid) {\n";
1874 file << tab(4) << "StringBuilder message = new StringBuilder();\n";
1878 writeJavaAppendVectorOutputToMessage(file, 4, p);
1880 writeJavaAppendVectorInputToMessage(file, 4, p);
1884 file << tab(4) << "assertTrue(\"Incorrect output for " << mJavaCheckMethodName << "\" +\n";
1885 file << tab(6) << "(relaxed ? \"_relaxed\" : \"\") + \":\\n\" + message.toString(), valid);\n";
1886 file << tab(3) << "}\n";
1887 file << tab(2) << "}\n";
1888 file << tab(1) << "}\n\n";
1891 void Permutation::writeJavaCallToRs(ofstream& file, bool relaxed, bool generateCallToVerifier) const {
1897 file << tab(2) << "try {\n";
1901 writeJavaOutputAllocationDefinition(file, tab(3), p);
1908 file << tab(3) << script << ".set_" << p.rsAllocName << "(" << p.javaAllocName
1913 file << tab(3) << script << ".forEach_" << mRsKernelName << "(";
1916 file << mParams[mFirstInputIndex]->javaAllocName;
1921 file << ", ";
1923 file << mParams[mReturnIndex]->variableName << ");\n";
1927 file << tab(3) << mJavaVerifyMethodName << "(";
1930 file << p.variableName << ", ";
1934 file << "true";
1936 file << "false";
1938 file << ");\n";
1940 file << tab(2) << "} catch (Exception e) {\n";
1941 file << tab(3) << "throw new RSRuntimeException(\"RenderScript. Can't invoke forEach_"
1943 file << tab(2) << "}\n";