Sharp upper bound for lifespan of solutions to some critical semilinear parabolic, dispersive and hyperbolic equations via a test function method