Integrating by parts, where did I go wrong? Suppose u satisfies $$\left(\partial_{t}^{2}-\partial_{x}^{2}\right) u(x, t)=0,(x, t) \in \mathbb{R} \times(0, \infty)$$
$ $
I'm trying to show:
$$\int_{\mathbb{R}} \int_{0}^{\infty} u(x, t)\left(\partial_{t}^{2}-\partial_{x}^{2}\right) \phi(x, t) \mathrm{d} t \mathrm{~d} x=\int_{\mathbb{R}} \phi(x, 0) h(x)-g(x) \partial_{t} \phi(x, 0) \mathrm{d} x$$
Where $u(x, 0)=g(x), \partial_{t} u(x, 0)=h(x), x \in \mathbb{R}$
I have:
Multiply the wave equation by $\phi$ and integrate over $\mathbb{R}\times(0,\infty)$
$$
\begin{gathered}
\left.\int_{\mathbb{R}} \phi(x, t) u_{t}(x, t)\right|_{0} ^{\infty}-\int_{\mathbb{R}} \int_{0}^{\infty} u_{t}(x, t) \phi_{t}-u_{x x}(x, t) \phi(x, t) d t d x \\
=\int_{\mathbb{R}} \phi(x, t) h(x) d x-\int_{\mathbb{R}} \int_{0}^{\infty} u_{t}(x, t) \phi_{t}-u_{x x}(x, t) \phi(x, t) d t d x \\
=\int_{\mathbb{R}} \phi(x, 0) h(x)-\phi_{t}(x, 0) g(x) d x+\int_{\mathbb{R}} \int_{0}^{\infty} u(x, t) \phi_{t t}-u_{x x}(x, t) \phi(x, t) d t d x \\
=\int_{\mathbb{R}} \phi(x, 0) h(x)-\phi_{t}(x, 0) g(x) d x+\int_{\mathbb{R}} \int_{0}^{\infty} u(x, t) \phi_{t t}-u(x, t) \phi_{x x}(x, t) d t d x-\int_{0}^{\infty}( \phi u_{x}-\phi_{x}u)|_\mathbb{R}dt
\end{gathered}
$$
Where did I go wrong?
 A: So if you are trying to show
$$\int_{\mathbb{R}} \int_{0}^{\infty} u(x, t)\left(\partial_{t}^{2}-\partial_{x}^{2}\right) \phi(x, t) \mathrm{d} t \mathrm{~d} x=\int_{\mathbb{R}} \phi(x, 0) h(x)-g(x) \partial_{t} \phi(x, 0) \mathrm{d} x$$
why do not simply start with the LHS?
$$\begin{align}&\int_\mathbb{R} \int_0^\infty u \phi_{tt}  -u \phi_{xx} \mathrm d t \mathrm d x \\
\overset{\text{Fubini}}{\Rightarrow}=& \int_\mathbb{R} \int_0^\infty u \phi_{tt}   \mathrm d t \mathrm d x - \int_0^\infty \int_\mathbb{R} u \phi_{xx} \mathrm d x \mathrm d t \\
\overset{\text{Int. by parts}}{\Rightarrow} = &\int_\mathbb{R} u(t)\phi_t(t) \Big \vert_0^\infty - \int_0^\infty u_t \phi_{t} \mathrm d t \mathrm d x  - \int_0^\infty u(x)\phi_x(x) \Big \vert_\mathbb{R} - \int_\mathbb{R} u_x \phi_{x} \mathrm d x \mathrm d t\end{align}$$
Typically test functions are chosen such that they have compact support.
Here this could be something like $\phi \in H_c^2(\mathbb{R} \times [0, \infty ) )$ which implies $\lim_{x \to \pm \infty} \phi(x,t) = 0, \lim_{t \to \infty} \phi(x, t)= 0$. Same holds for $\phi_x, \phi_t$.
Invoking this gives
$$ \begin{align}&\int_\mathbb{R} -u(x, 0) \phi_t(x, 0) - \int_0^\infty u_t \phi_{t} \mathrm d t \mathrm d x + \int_0^\infty \int_\mathbb{R} u_x \phi_{x} \mathrm d x \mathrm d t \\
\overset{\text{Int. by parts}}{\Rightarrow} =& \int_\mathbb{R} -g(x) \phi_t(x, 0) - u_t \phi \big \vert_0^\infty + \int_0^\infty u_{tt} \phi \mathrm d t \mathrm d x + \int_0^\infty u_x(x) \phi(x) \big \vert_\mathbb{R} - \int_\mathbb{R} u_{xx} \phi \mathrm d x \mathrm d t \end{align}
$$
Again, using the compact support of $\phi$ gives
$$ \begin{align} &\int_\mathbb{R} -g(x) \phi_t(x, 0) + u_t(x, 0) \phi(x, 0) \mathrm d x + \int_\mathbb{R} \int_0^\infty u_{tt} \phi \mathrm d t \mathrm dx -  \int_0^\infty \int_\mathbb{R} u_{xx} \phi \mathrm d x \mathrm d t \\
\overset{\text{Fubini}}{\Rightarrow}=&  \int_\mathbb{R} h(x) \phi(x, 0) - g(x) \phi_t(x, 0) \mathrm d x + \int_\mathbb{R} \int_0^\infty (u_{tt} - u_ {xx}) \phi \mathrm d t \mathrm d x\end{align}$$
which is the desired outcome for $u$ satisfying the wave equation.
Basically you can do all the steps in reverse order (if starting from $\int_\mathbb{R} \int_0^\infty \phi (u_{xx} - u_{tt} ) \mathrm d t \mathrm d x$) to get the same result.
