From: David Steele Date: Mon, 20 Jun 2016 13:57:04 +0000 (+0100) Subject: Updated test harness to add map of named parameters to Gl traces. X-Git-Tag: dali_1.1.40~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F95%2F75595%2F2;p=platform%2Fcore%2Fuifw%2Fdali-core.git Updated test harness to add map of named parameters to Gl traces. As well as storing the parameter list as a single string, have added (for GlAbstraction) a named parameter map. This should prevent changes to the trace from breaking existing tests in the future, and also provides a slightly easier to use method for searching for methods with specific parameters. Change-Id: Iab726d2e2bcae805fa39b48c0675ea5a96faa64d Signed-off-by: David Steele --- diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index f910d51be..9a93c8e5e 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -73,7 +73,11 @@ public: { std::stringstream out; out << program << ", " << shader; - mShaderTrace.PushCall("AttachShader", out.str()); + + TraceCallStack::NamedParams namedParams; + namedParams["program"] = ToString(program); + namedParams["shader"] = ToString(shader); + mShaderTrace.PushCall("AttachShader", out.str(), namedParams); } inline void BindAttribLocation( GLuint program, GLuint index, const char* name ) @@ -141,7 +145,12 @@ public: std::stringstream out; out << target << ", " << texture; - mTextureTrace.PushCall("BindTexture", out.str()); + + TraceCallStack::NamedParams namedParams; + namedParams["target"] = ToString(target); + namedParams["texture"] = ToString(texture); + + mTextureTrace.PushCall("BindTexture", out.str(), namedParams); } inline void BlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) @@ -278,7 +287,10 @@ public: { std::stringstream out; out << shader; - mShaderTrace.PushCall("CompileShader", out.str()); + TraceCallStack::NamedParams namedParams; + namedParams["shader"] = ToString(shader); + + mShaderTrace.PushCall("CompileShader", out.str(), namedParams); } inline void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data) @@ -310,7 +322,10 @@ public: { std::stringstream out; out << type; - mShaderTrace.PushCall("CreateShader", out.str()); + + TraceCallStack::NamedParams namedParams; + namedParams["type"] = ToString(type); + mShaderTrace.PushCall("CreateShader", out.str(), namedParams); return ++mLastShaderIdUsed; } @@ -319,7 +334,11 @@ public: { std::stringstream out; out << mode; - mCullFaceTrace.PushCall("CullFace", out.str()); + + TraceCallStack::NamedParams namedParams; + namedParams["program"] = ToString(mode); + + mCullFaceTrace.PushCall("CullFace", out.str(), namedParams); } inline void DeleteBuffers(GLsizei n, const GLuint* buffers) @@ -334,7 +353,11 @@ public: { std::stringstream out; out << program; - mShaderTrace.PushCall("DeleteProgram", out.str()); + + TraceCallStack::NamedParams namedParams; + namedParams["program"] = ToString(program); + + mShaderTrace.PushCall("DeleteProgram", out.str(), namedParams); } inline void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers) @@ -345,7 +368,11 @@ public: { std::stringstream out; out << shader; - mShaderTrace.PushCall("DeleteShader", out.str()); + + TraceCallStack::NamedParams namedParams; + namedParams["shader"] = ToString(shader); + + mShaderTrace.PushCall("DeleteShader", out.str(), namedParams); } inline void DeleteTextures(GLsizei n, const GLuint* textures) @@ -353,13 +380,19 @@ public: std::stringstream out; out << n << ", " << textures << " = ["; + TraceCallStack::NamedParams namedParams; + for(GLsizei i=0; i namespace Dali { + +std::string ToString(int x) +{ + std::stringstream out; + out << x; + return out.str(); +} + +std::string ToString(unsigned int x) +{ + std::stringstream out; + out << x; + return out.str(); +} + +std::string ToString(float x) +{ + std::stringstream out; + out << x; + return out.str(); +} + /** * Constructor */ @@ -45,10 +68,17 @@ void TraceCallStack::PushCall(std::string method, std::string params) { if(mTraceActive) { - std::vector< std::string > functionCall; - functionCall.push_back(method); - functionCall.push_back(params); - mCallStack.push_back( functionCall ); + FunctionCall stackFrame(method, params); + mCallStack.push_back( stackFrame ); + } +} + +void TraceCallStack::PushCall(std::string method, std::string params, const TraceCallStack::NamedParams& altParams) +{ + if(mTraceActive) + { + FunctionCall stackFrame(method, params, altParams); + mCallStack.push_back( stackFrame ); } } @@ -62,7 +92,7 @@ bool TraceCallStack::FindMethod(std::string method) const bool found = false; for( size_t i=0; i < mCallStack.size(); i++ ) { - if( 0 == mCallStack[i][0].compare(method) ) + if( 0 == mCallStack[i].method.compare(method) ) { found = true; break; @@ -76,7 +106,7 @@ int TraceCallStack::CountMethod(std::string method) const int numCalls = 0; for( size_t i=0; i < mCallStack.size(); i++ ) { - if( 0 == mCallStack[i][0].compare(method) ) + if( 0 == mCallStack[i].method.compare(method) ) { numCalls++; } @@ -95,6 +125,12 @@ bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) return FindIndexFromMethodAndParams( method, params ) > -1; } +bool TraceCallStack::FindMethodAndParams(std::string method, const NamedParams& params) const +{ + return FindIndexFromMethodAndParams( method, params ) > -1; +} + + /** * Search for a method in the stack with the given parameter list * @param[in] method The name of the method @@ -106,7 +142,7 @@ int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string int index = -1; for( size_t i=0; i < mCallStack.size(); i++ ) { - if( 0 == mCallStack[i][0].compare(method) && 0 == mCallStack[i][1].compare(params) ) + if( 0 == mCallStack[i].method.compare(method) && 0 == mCallStack[i].paramList.compare(params) ) { index = i; break; @@ -115,6 +151,35 @@ int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string return index; } +int TraceCallStack::FindIndexFromMethodAndParams(std::string method, const TraceCallStack::NamedParams& params) const +{ + int index = -1; + for( size_t i=0; i < mCallStack.size(); i++ ) + { + if( 0 == mCallStack[i].method.compare(method) ) + { + // Test each of the passed in parameters: + bool match = true; + for( NamedParams::const_iterator iter = params.begin() ; iter != params.end() ; ++iter ) + { + NamedParams::const_iterator paramIter = mCallStack[i].namedParams.find(iter->first); + if( paramIter == params.end() || paramIter->second.compare(iter->second) != 0 ) + { + match = false; + break; + } + } + if( match == true ) + { + index = i; + break; + } + } + } + return index; +} + + /** * Test if the given method and parameters are at a given index in the stack * @param[in] index Index in the call stack @@ -123,7 +188,7 @@ int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string */ bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const { - return ( 0 == mCallStack[index][0].compare(method) && 0 == mCallStack[index][1].compare(params) ); + return ( 0 == mCallStack[index].method.compare(method) && 0 == mCallStack[index].paramList.compare(params) ); } /** diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h b/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h index d319487f4..32375a682 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h @@ -20,9 +20,13 @@ #include #include +#include namespace Dali { +std::string ToString(int x); +std::string ToString(unsigned int x); +std::string ToString(float x); /** * Helper class to track method calls in the abstraction and search for them in test cases @@ -30,6 +34,9 @@ namespace Dali class TraceCallStack { public: + /// Typedef for passing and storing named parameters + typedef std::map< std::string, std::string > NamedParams; + /** * Constructor */ @@ -54,6 +61,13 @@ public: */ void PushCall(std::string method, std::string params); + /** + * Push a call onto the stack if the trace is active + * @param[in] method The name of the method + * @param[in] params A comma separated list of parameter values + * @param[in] altParams A map of named parameter values + */ + void PushCall(std::string method, std::string params, const NamedParams& altParams); /** * Search for a method in the stack @@ -77,6 +91,14 @@ public: */ bool FindMethodAndParams(std::string method, std::string params) const; + /** + * Search for a method in the stack with the given parameter list + * @param[in] method The name of the method + * @param[in] params A map of named parameters to test for + * @return true if the method was in the stack + */ + bool FindMethodAndParams(std::string method, const NamedParams& params) const; + /** * Search for a method in the stack with the given parameter list * @param[in] method The name of the method @@ -85,6 +107,14 @@ public: */ int FindIndexFromMethodAndParams(std::string method, std::string params) const; + /** + * Search for a method in the stack with the given parameter list + * @param[in] method The name of the method + * @param[in] params A map of named parameter values to match + * @return index in the stack where the method was found or -1 otherwise + */ + int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const; + /** * Test if the given method and parameters are at a given index in the stack * @param[in] index Index in the call stack @@ -98,15 +128,25 @@ public: */ void Reset(); - /** - * Get the call stack - * @return The call stack object (Vector of vector[2] of method/paramlist strings) - */ - inline const std::vector< std::vector< std::string > >& GetCallStack() { return mCallStack; } - private: bool mTraceActive; ///< True if the trace is active - std::vector< std::vector< std::string > > mCallStack; ///< The call stack + + struct FunctionCall + { + std::string method; + std::string paramList; + NamedParams namedParams; + FunctionCall( const std::string& aMethod, const std::string& aParamList ) + : method( aMethod ), paramList( aParamList ) + { + } + FunctionCall( const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams ) + : method( aMethod ), paramList( aParamList ), namedParams( altParams ) + { + } + }; + + std::vector< FunctionCall > mCallStack; ///< The call stack }; } // namespace dali