Count a subset of the ballots by hand, if they match, then your confidence in the system increases. Continue verification until confidence in the system reaches acceptable levels.
The voting machines that I've used recently are systems that automatically count paper ballots as they are submitted. There's a clear chain of custody with these, and these results have a 100% audit trail. Not only that, but these systems work in tandem to identify errors in either system.
The likelihood of discovering some injected irregularity is pretty high. Especially since we have systems in place for automatic hand-recounts in tight races. So if the system were going to nefariously alter the election outcome, it would have to be done at such a magnitude as to exceed the threshold for automatic hand-recounts, but be small enough to not be discovered. Plus, candidates can request a manual recount, further increasing the reliability of the system.
As with all systems where reliability is paramount: it's important to lean on redundancy in the system, rather than try to make a single component as reliable as possible.
Voting machines are inherently a challenge to verify. Even if the voter herself compiles source code and loads the resulting object into the machine before voting, it's impossible for her to verify the hardware is actually using that object. The paper ballots produced by these machines have marks next to candidates, but they also have an opaque bar code and that's what gets scanned when votes are "recounted". On top of all this, considering the design and code of these machines to be commercial secrets ensures error and distrust.